Skip to content

Commit 37b1ad6

Browse files
authored
Functions Cleanup (#15119)
1 parent 91b35d5 commit 37b1ad6

File tree

7 files changed

+15
-87
lines changed

7 files changed

+15
-87
lines changed

FirebaseFunctions/Sources/Callable+Codable.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ public struct Callable<Request: Encodable, Response: Decodable>: Sendable {
133133
/// - Throws: An error if the callable fails to complete
134134
///
135135
/// - Returns: The decoded `Response` value
136-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
137136
public func call(_ data: Request) async throws -> Response {
138137
let encoded = try encoder.encode(data)
139138
let result = try await callable.call(encoded)
@@ -160,7 +159,6 @@ public struct Callable<Request: Encodable, Response: Decodable>: Sendable {
160159
/// - Parameters:
161160
/// - data: Parameters to pass to the trigger.
162161
/// - Returns: The decoded `Response` value
163-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
164162
public func callAsFunction(_ data: Request) async throws -> Response {
165163
return try await call(data)
166164
}
@@ -174,7 +172,7 @@ private protocol StreamResponseProtocol {}
174172
///
175173
/// This can be used as the generic `Response` parameter to ``Callable`` to receive both the
176174
/// yielded messages and final return value of the streaming callable function.
177-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
175+
@available(macOS 12.0, watchOS 8.0, *)
178176
public enum StreamResponse<Message: Decodable & Sendable, Result: Decodable & Sendable>: Decodable,
179177
Sendable,
180178
StreamResponseProtocol {

FirebaseFunctions/Sources/Functions.swift

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ enum FunctionsConstants {
386386
return URL(string: "https://\(region)-\(projectID).cloudfunctions.net/\(name)")
387387
}
388388

389-
@available(iOS 13, macCatalyst 13, macOS 10.15, tvOS 13, watchOS 7, *)
390389
func callFunction(at url: URL,
391390
withObject data: Any?,
392391
options: HTTPSCallableOptions?,
@@ -408,49 +407,6 @@ enum FunctionsConstants {
408407
}
409408
}
410409

411-
private func callFunction(url: URL,
412-
withObject data: Any?,
413-
options: HTTPSCallableOptions?,
414-
timeout: TimeInterval,
415-
context: FunctionsContext,
416-
completion: @escaping @MainActor (Result<HTTPSCallableResult, Error>)
417-
-> Void) {
418-
let fetcher: GTMSessionFetcher
419-
do {
420-
fetcher = try makeFetcher(
421-
url: url,
422-
data: data,
423-
options: options,
424-
timeout: timeout,
425-
context: context
426-
)
427-
} catch {
428-
DispatchQueue.main.async {
429-
completion(.failure(error))
430-
}
431-
return
432-
}
433-
434-
fetcher.beginFetch { [self] data, error in
435-
let result: Result<HTTPSCallableResult, any Error>
436-
if let error {
437-
result = .failure(processedError(fromResponseError: error, endpointURL: url))
438-
} else if let data {
439-
do {
440-
result = try .success(callableResult(fromResponseData: data, endpointURL: url))
441-
} catch {
442-
result = .failure(error)
443-
}
444-
} else {
445-
result = .failure(FunctionsError(.internal))
446-
}
447-
448-
DispatchQueue.main.async {
449-
completion(result)
450-
}
451-
}
452-
}
453-
454410
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
455411
func stream(at url: URL,
456412
data: SendableWrapper?,
@@ -556,7 +512,7 @@ enum FunctionsConstants {
556512
}
557513
}
558514

559-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
515+
@available(macOS 12.0, watchOS 8.0, *)
560516
private func callableStreamResult(fromResponseData data: Data,
561517
endpointURL url: URL) throws -> sending JSONStreamResponse {
562518
let data = try processedData(fromResponseData: data, endpointURL: url)

FirebaseFunctions/Sources/HTTPSCallable.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public final class HTTPSCallable: NSObject, Sendable {
160160
/// - Parameter data: Parameters to pass to the trigger.
161161
/// - Throws: An error if the Cloud Functions invocation failed.
162162
/// - Returns: The result of the call.
163-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
164163
public func call(_ data: Any? = nil) async throws -> sending HTTPSCallableResult {
165164
try await functions
166165
.callFunction(at: url, withObject: data, options: options, timeout: timeoutInterval)

FirebaseFunctions/Sources/Internal/FunctionsContext.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct FunctionsContextProvider: Sendable {
3636
self.appCheck = appCheck
3737
}
3838

39-
@available(iOS 13, macCatalyst 13, macOS 10.15, tvOS 13, watchOS 7, *)
4039
func context(options: HTTPSCallableOptions?) async throws -> FunctionsContext {
4140
async let authToken = auth?.getToken(forcingRefresh: false)
4241
async let appCheckToken = getAppCheckToken(options: options)
@@ -52,7 +51,6 @@ struct FunctionsContextProvider: Sendable {
5251
)
5352
}
5453

55-
@available(iOS 13, macCatalyst 13, macOS 10.15, tvOS 13, watchOS 7, *)
5654
private func getAppCheckToken(options: HTTPSCallableOptions?) async -> String? {
5755
guard
5856
options?.requireLimitedUseAppCheckTokens != true,
@@ -62,7 +60,6 @@ struct FunctionsContextProvider: Sendable {
6260
return tokenResult.token
6361
}
6462

65-
@available(iOS 13, macCatalyst 13, macOS 10.15, tvOS 13, watchOS 7, *)
6663
private func getLimitedUseAppCheckToken(options: HTTPSCallableOptions?) async -> String? {
6764
// At the moment, `await` doesn’t get along with Objective-C’s optional protocol methods.
6865
await withCheckedContinuation { (continuation: CheckedContinuation<String?, Never>) in

FirebaseFunctions/Tests/CombineUnit/HTTPSCallableTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class MockFunctions: Functions, @unchecked Sendable {
5454
}
5555
}
5656

57-
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
5857
class HTTPSCallableTests: XCTestCase {
5958
func testCallWithoutParametersSuccess() {
6059
// given

FirebaseFunctions/Tests/Integration/IntegrationTests.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class IntegrationTests: XCTestCase {
119119
}
120120
}
121121

122-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
123122
func testDataAsync() async throws {
124123
let data = DataTestRequest(
125124
bool: true,
@@ -174,7 +173,6 @@ class IntegrationTests: XCTestCase {
174173
}
175174
}
176175

177-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
178176
func testScalarAsync() async throws {
179177
let byName = functions.httpsCallable(
180178
"scalarTest",
@@ -193,7 +191,6 @@ class IntegrationTests: XCTestCase {
193191
}
194192
}
195193

196-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
197194
func testScalarAsyncAlternateSignature() async throws {
198195
let byName: Callable<Int16, Int> = functions.httpsCallable("scalarTest")
199196
let byURL: Callable<Int16, Int> = functions.httpsCallable(emulatorURL("scalarTest"))
@@ -241,7 +238,6 @@ class IntegrationTests: XCTestCase {
241238
}
242239
}
243240

244-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
245241
func testTokenAsync() async throws {
246242
// Recreate functions with a token.
247243
let functions = Functions(
@@ -297,7 +293,6 @@ class IntegrationTests: XCTestCase {
297293
}
298294
}
299295

300-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
301296
func testFCMTokenAsync() async throws {
302297
let byName = functions.httpsCallable(
303298
"FCMTokenTest",
@@ -342,7 +337,6 @@ class IntegrationTests: XCTestCase {
342337
}
343338
}
344339

345-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
346340
func testNullAsync() async throws {
347341
let byName = functions.httpsCallable(
348342
"nullTest",
@@ -391,7 +385,6 @@ class IntegrationTests: XCTestCase {
391385
}
392386
}
393387

394-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
395388
func testMissingResultAsync() async {
396389
let byName = functions.httpsCallable(
397390
"missingResultTest",
@@ -445,7 +438,6 @@ class IntegrationTests: XCTestCase {
445438
}
446439
}
447440

448-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
449441
func testUnhandledErrorAsync() async {
450442
let byName = functions.httpsCallable(
451443
"unhandledErrorTest",
@@ -498,7 +490,6 @@ class IntegrationTests: XCTestCase {
498490
waitForExpectations(timeout: 5)
499491
}
500492

501-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
502493
func testUnknownErrorAsync() async {
503494
let byName = functions.httpsCallable(
504495
"unknownErrorTest",
@@ -553,7 +544,6 @@ class IntegrationTests: XCTestCase {
553544
}
554545
}
555546

556-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
557547
func testExplicitErrorAsync() async {
558548
let byName = functions.httpsCallable(
559549
"explicitErrorTest",
@@ -608,7 +598,6 @@ class IntegrationTests: XCTestCase {
608598
}
609599
}
610600

611-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
612601
func testHttpErrorAsync() async {
613602
let byName = functions.httpsCallable(
614603
"httpErrorTest",
@@ -661,7 +650,6 @@ class IntegrationTests: XCTestCase {
661650
}
662651
}
663652

664-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
665653
func testThrowErrorAsync() async {
666654
let byName = functions.httpsCallable(
667655
"throwTest",
@@ -716,7 +704,6 @@ class IntegrationTests: XCTestCase {
716704
}
717705
}
718706

719-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
720707
func testTimeoutAsync() async {
721708
var byName = functions.httpsCallable(
722709
"timeoutTest",
@@ -778,7 +765,6 @@ class IntegrationTests: XCTestCase {
778765
}
779766
}
780767

781-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
782768
func testCallAsFunctionAsync() async throws {
783769
let data = DataTestRequest(
784770
bool: true,
@@ -841,7 +827,6 @@ class IntegrationTests: XCTestCase {
841827
}
842828
}
843829

844-
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
845830
func testInferredTyesAsync() async throws {
846831
let data = DataTestRequest(
847832
bool: true,

FirebaseFunctions/Tests/Unit/FunctionsAPITests.swift

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,13 @@ final class FunctionsAPITests: XCTestCase {
8585
}
8686
}
8787

88-
if #available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
89-
// async/await is a Swift Concurrency feature available on iOS 13+ and macOS 10.15+
90-
Task {
91-
do {
92-
let data: Any? = nil
93-
let result = try await callableRef.call(data)
94-
_ = result.data
95-
} catch {
96-
// ...
97-
}
88+
Task {
89+
do {
90+
let data: Any? = nil
91+
let result = try await callableRef.call(data)
92+
_ = result.data
93+
} catch {
94+
// ...
9895
}
9996
}
10097

@@ -106,15 +103,12 @@ final class FunctionsAPITests: XCTestCase {
106103
}
107104
}
108105

109-
if #available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
110-
// async/await is a Swift Concurrency feature available on iOS 13+ and macOS 10.15+
111-
Task {
112-
do {
113-
let result = try await callableRef.call()
114-
_ = result.data
115-
} catch {
116-
// ...
117-
}
106+
Task {
107+
do {
108+
let result = try await callableRef.call()
109+
_ = result.data
110+
} catch {
111+
// ...
118112
}
119113
}
120114

0 commit comments

Comments
 (0)