Skip to content

Commit cac7810

Browse files
authored
feat(storage): Remove the async throws from the apis that return task (#2543)
1 parent 5884eb3 commit cac7810

File tree

12 files changed

+123
-76
lines changed

12 files changed

+123
-76
lines changed

Amplify/Categories/Storage/StorageCategory+ClientBehavior.swift

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,60 @@ import Foundation
1010
extension StorageCategory: StorageCategoryBehavior {
1111

1212
@discardableResult
13-
public func getURL(key: String,
14-
options: StorageGetURLOperation.Request.Options? = nil) async throws -> URL {
13+
public func getURL(
14+
key: String,
15+
options: StorageGetURLOperation.Request.Options? = nil
16+
) async throws -> URL {
1517
try await plugin.getURL(key: key, options: options)
1618
}
1719

1820
@discardableResult
19-
public func downloadData(key: String,
20-
options: StorageDownloadDataOperation.Request.Options? = nil) async throws -> StorageDownloadDataTask {
21-
try await plugin.downloadData(key: key, options: options)
21+
public func downloadData(
22+
key: String,
23+
options: StorageDownloadDataOperation.Request.Options? = nil
24+
) -> StorageDownloadDataTask {
25+
plugin.downloadData(key: key, options: options)
2226
}
2327

2428
@discardableResult
25-
public func downloadFile(key: String,
26-
local: URL,
27-
options: StorageDownloadFileOperation.Request.Options?) async throws -> StorageDownloadFileTask {
28-
try await plugin.downloadFile(key: key, local: local, options: options)
29+
public func downloadFile(
30+
key: String,
31+
local: URL,
32+
options: StorageDownloadFileOperation.Request.Options? = nil
33+
) -> StorageDownloadFileTask {
34+
plugin.downloadFile(key: key, local: local, options: options)
2935
}
3036

3137
@discardableResult
32-
public func uploadData(key: String,
33-
data: Data,
34-
options: StorageUploadDataOperation.Request.Options? = nil) async throws -> StorageUploadDataTask {
35-
try await plugin.uploadData(key: key, data: data, options: options)
38+
public func uploadData(
39+
key: String,
40+
data: Data,
41+
options: StorageUploadDataOperation.Request.Options? = nil
42+
) -> StorageUploadDataTask {
43+
plugin.uploadData(key: key, data: data, options: options)
3644
}
3745

3846
@discardableResult
39-
public func uploadFile(key: String,
40-
local: URL,
41-
options: StorageUploadFileOperation.Request.Options? = nil) async throws -> StorageUploadFileTask {
42-
try await plugin.uploadFile(key: key, local: local, options: options)
47+
public func uploadFile(
48+
key: String,
49+
local: URL,
50+
options: StorageUploadFileOperation.Request.Options? = nil
51+
) -> StorageUploadFileTask {
52+
plugin.uploadFile(key: key, local: local, options: options)
4353
}
4454

4555
@discardableResult
46-
public func remove(key: String,
47-
options: StorageRemoveRequest.Options? = nil) async throws -> String {
56+
public func remove(
57+
key: String,
58+
options: StorageRemoveRequest.Options? = nil
59+
) async throws -> String {
4860
try await plugin.remove(key: key, options: options)
4961
}
5062

5163
@discardableResult
52-
public func list(options: StorageListOperation.Request.Options? = nil) async throws -> StorageListResult {
64+
public func list(
65+
options: StorageListOperation.Request.Options? = nil
66+
) async throws -> StorageListResult {
5367
try await plugin.list(options: options)
5468
}
5569

Amplify/Categories/Storage/StorageCategoryBehavior.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public protocol StorageCategoryBehavior {
2828
/// - Returns: A task that provides progress updates and the key which was used to download
2929
@discardableResult
3030
func downloadData(key: String,
31-
options: StorageDownloadDataOperation.Request.Options?) async throws -> StorageDownloadDataTask
31+
options: StorageDownloadDataOperation.Request.Options?) -> StorageDownloadDataTask
3232

3333
/// Download to file the object from storage.
3434
///
@@ -40,7 +40,7 @@ public protocol StorageCategoryBehavior {
4040
@discardableResult
4141
func downloadFile(key: String,
4242
local: URL,
43-
options: StorageDownloadFileOperation.Request.Options?) async throws -> StorageDownloadFileTask
43+
options: StorageDownloadFileOperation.Request.Options?) -> StorageDownloadFileTask
4444

4545
/// Upload data to storage
4646
///
@@ -52,7 +52,7 @@ public protocol StorageCategoryBehavior {
5252
@discardableResult
5353
func uploadData(key: String,
5454
data: Data,
55-
options: StorageUploadDataOperation.Request.Options?) async throws -> StorageUploadDataTask
55+
options: StorageUploadDataOperation.Request.Options?) -> StorageUploadDataTask
5656

5757
/// Upload local file to storage
5858
///
@@ -64,7 +64,7 @@ public protocol StorageCategoryBehavior {
6464
@discardableResult
6565
func uploadFile(key: String,
6666
local: URL,
67-
options: StorageUploadFileOperation.Request.Options?) async throws -> StorageUploadFileTask
67+
options: StorageUploadFileOperation.Request.Options?) -> StorageUploadFileTask
6868

6969
/// Delete object from storage
7070
///

AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/AWSS3StoragePlugin+AsyncClientBehavior.swift

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import AWSPluginsCore
1414
extension AWSS3StoragePlugin {
1515

1616
@discardableResult
17-
public func getURL(key: String,
18-
options: StorageGetURLOperation.Request.Options?) async throws -> URL {
17+
public func getURL(
18+
key: String,
19+
options: StorageGetURLOperation.Request.Options? = nil
20+
) async throws -> URL {
1921
let options = options ?? StorageGetURLRequest.Options()
2022
let request = StorageGetURLRequest(key: key, options: options)
2123
let operation = AWSS3StorageGetURLOperation(request,
@@ -29,8 +31,10 @@ extension AWSS3StoragePlugin {
2931
}
3032

3133
@discardableResult
32-
public func downloadData(key: String,
33-
options: StorageDownloadDataOperation.Request.Options? = nil) async throws -> StorageDownloadDataTask {
34+
public func downloadData(
35+
key: String,
36+
options: StorageDownloadDataOperation.Request.Options? = nil
37+
) -> StorageDownloadDataTask {
3438
let options = options ?? StorageDownloadDataRequest.Options()
3539
let request = StorageDownloadDataRequest(key: key, options: options)
3640
let operation = AWSS3StorageDownloadDataOperation(request,
@@ -44,9 +48,11 @@ extension AWSS3StoragePlugin {
4448
}
4549

4650
@discardableResult
47-
public func downloadFile(key: String,
48-
local: URL,
49-
options: StorageDownloadFileOperation.Request.Options?) async throws -> StorageDownloadFileTask {
51+
public func downloadFile(
52+
key: String,
53+
local: URL,
54+
options: StorageDownloadFileOperation.Request.Options? = nil
55+
) -> StorageDownloadFileTask {
5056
let options = options ?? StorageDownloadFileRequest.Options()
5157
let request = StorageDownloadFileRequest(key: key, local: local, options: options)
5258
let operation = AWSS3StorageDownloadFileOperation(request,
@@ -60,9 +66,11 @@ extension AWSS3StoragePlugin {
6066
}
6167

6268
@discardableResult
63-
public func uploadData(key: String,
64-
data: Data,
65-
options: StorageUploadDataOperation.Request.Options?) async throws -> StorageUploadDataTask {
69+
public func uploadData(
70+
key: String,
71+
data: Data,
72+
options: StorageUploadDataOperation.Request.Options? = nil
73+
) -> StorageUploadDataTask {
6674
let options = options ?? StorageUploadDataRequest.Options()
6775
let request = StorageUploadDataRequest(key: key, data: data, options: options)
6876
let operation = AWSS3StorageUploadDataOperation(request,
@@ -76,9 +84,11 @@ extension AWSS3StoragePlugin {
7684
}
7785

7886
@discardableResult
79-
public func uploadFile(key: String,
80-
local: URL,
81-
options: StorageUploadFileOperation.Request.Options?) async throws -> StorageUploadFileTask {
87+
public func uploadFile(
88+
key: String,
89+
local: URL,
90+
options: StorageUploadFileOperation.Request.Options? = nil
91+
) -> StorageUploadFileTask {
8292
let options = options ?? StorageUploadFileRequest.Options()
8393
let request = StorageUploadFileRequest(key: key, local: local, options: options)
8494
let operation = AWSS3StorageUploadFileOperation(request,
@@ -92,8 +102,10 @@ extension AWSS3StoragePlugin {
92102
}
93103

94104
@discardableResult
95-
public func remove(key: String,
96-
options: StorageRemoveOperation.Request.Options?) async throws -> String {
105+
public func remove(
106+
key: String,
107+
options: StorageRemoveOperation.Request.Options? = nil
108+
) async throws -> String {
97109
let options = options ?? StorageRemoveRequest.Options()
98110
let request = StorageRemoveRequest(key: key, options: options)
99111
let operation = AWSS3StorageRemoveOperation(request,
@@ -106,7 +118,9 @@ extension AWSS3StoragePlugin {
106118
return try await taskAdapter.value
107119
}
108120

109-
public func list(options: StorageListRequest.Options? = nil) async throws -> StorageListResult {
121+
public func list(
122+
options: StorageListRequest.Options? = nil
123+
) async throws -> StorageListResult {
110124
let options = options ?? StorageListRequest.Options()
111125
let request = StorageListRequest(options: options)
112126
let operation = AWSS3StorageListOperation(request,

AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginProgressTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AWSS3StoragePluginProgressTests: AWSS3StoragePluginTestBase {
3333
let completionReceived = expectation(description: "resultReceived")
3434
let progressReceived = expectation(description: "progressReceived")
3535
progressReceived.assertForOverFulfill = false
36-
let uploadOperation = try await Amplify.Storage.uploadData(
36+
let uploadOperation = Amplify.Storage.uploadData(
3737
key: key,
3838
data: .testDataOfSize(.bytes(100)))
3939

@@ -63,7 +63,7 @@ class AWSS3StoragePluginProgressTests: AWSS3StoragePluginTestBase {
6363
let key = "testUploadProgressDeliveryAfterCompletion-\(timestamp)"
6464

6565
// Wait for the upload to complete
66-
let uploadOperation = try await Amplify.Storage.uploadData(
66+
let uploadOperation = Amplify.Storage.uploadData(
6767
key: key,
6868
data: .testDataOfSize(.bytes(100))
6969
)

AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/AWSS3StoragePluginTestBase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ class AWSS3StoragePluginTestBase: XCTestCase {
6363

6464
func uploadTask(key: String, data: Data) async -> StorageUploadDataTask? {
6565
return await wait(name: "Upload Task created") {
66-
return try await Amplify.Storage.uploadData(key: key, data: data)
66+
return Amplify.Storage.uploadData(key: key, data: data)
6767
}
6868
}
6969

7070
func downloadTask(key: String) async -> StorageDownloadDataTask? {
7171
return await wait(name: "Upload Task created") {
72-
return try await Amplify.Storage.downloadData(key: key)
72+
return Amplify.Storage.downloadData(key: key)
7373
}
7474
}
7575

AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/ResumabilityTests/AWSS3StoragePluginGetDataResumabilityTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AWSS3StoragePluginDownloadDataResumabilityTests: AWSS3StoragePluginTestBas
2525
XCTAssertEqual(uploadKey, key)
2626

2727
Self.logger.debug("Downloading data")
28-
let task = try await Amplify.Storage.downloadData(key: key)
28+
let task = Amplify.Storage.downloadData(key: key)
2929

3030
let didPause = asyncExpectation(description: "did pause")
3131
let didContinue = asyncExpectation(description: "did continue", isInverted: true)
@@ -79,7 +79,7 @@ class AWSS3StoragePluginDownloadDataResumabilityTests: AWSS3StoragePluginTestBas
7979
let uploadKey = try await Amplify.Storage.uploadData(key: key, data: data).value
8080
XCTAssertEqual(uploadKey, key)
8181

82-
let task = try await Amplify.Storage.downloadData(key: key)
82+
let task = Amplify.Storage.downloadData(key: key)
8383

8484
let progressInvoked = asyncExpectation(description: "Progress invoked")
8585
Task {
@@ -133,7 +133,7 @@ class AWSS3StoragePluginDownloadDataResumabilityTests: AWSS3StoragePluginTestBas
133133
XCTAssertEqual(uploadKey, key)
134134

135135
Self.logger.debug("Downloading data")
136-
let task = try await Amplify.Storage.downloadData(key: key)
136+
let task = Amplify.Storage.downloadData(key: key)
137137

138138
let didCancel = asyncExpectation(description: "did cancel")
139139
let didContinue = asyncExpectation(description: "did continue", isInverted: true)

AmplifyPlugins/Storage/Tests/StorageHostApp/AWSS3StoragePluginIntegrationTests/ResumabilityTests/AWSS3StoragePluginPutDataResumabilityTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AWSS3StoragePluginUploadDataResumabilityTests: AWSS3StoragePluginTestBase
2020
try await testTask(timeout: 600) {
2121
let key = UUID().uuidString
2222
Self.logger.debug("Uploading data")
23-
let task = try await Amplify.Storage.uploadData(key: key, data: AWSS3StoragePluginTestBase.largeDataObject)
23+
let task = Amplify.Storage.uploadData(key: key, data: AWSS3StoragePluginTestBase.largeDataObject)
2424

2525
let didPause = asyncExpectation(description: "did pause")
2626
let didContinue = asyncExpectation(description: "did continue", isInverted: true)
@@ -71,7 +71,7 @@ class AWSS3StoragePluginUploadDataResumabilityTests: AWSS3StoragePluginTestBase
7171
try await testTask(timeout: 600) {
7272
let key = UUID().uuidString
7373
Self.logger.debug("Uploading data")
74-
let task = try await Amplify.Storage.uploadData(key: key, data: AWSS3StoragePluginTestBase.largeDataObject)
74+
let task = Amplify.Storage.uploadData(key: key, data: AWSS3StoragePluginTestBase.largeDataObject)
7575

7676
let progressInvoked = asyncExpectation(description: "Progress invoked")
7777
Task {
@@ -118,7 +118,7 @@ class AWSS3StoragePluginUploadDataResumabilityTests: AWSS3StoragePluginTestBase
118118
try await testTask(timeout: 600) {
119119
let key = UUID().uuidString
120120
Self.logger.debug("Uploading data")
121-
let task = try await Amplify.Storage.uploadData(key: key, data: AWSS3StoragePluginTestBase.largeDataObject)
121+
let task = Amplify.Storage.uploadData(key: key, data: AWSS3StoragePluginTestBase.largeDataObject)
122122

123123
let didCancel = asyncExpectation(description: "did cancel")
124124
let didContinue = asyncExpectation(description: "did continue", isInverted: true)

0 commit comments

Comments
 (0)