Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions FirebaseFunctions/Sources/Callable+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public struct Callable<Request: Encodable, Response: Decodable>: Sendable {
/// - Throws: An error if the callable fails to complete
///
/// - Returns: The decoded `Response` value
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
public func call(_ data: Request) async throws -> Response {
let encoded = try encoder.encode(data)
let result = try await callable.call(encoded)
Expand All @@ -160,7 +159,6 @@ public struct Callable<Request: Encodable, Response: Decodable>: Sendable {
/// - Parameters:
/// - data: Parameters to pass to the trigger.
/// - Returns: The decoded `Response` value
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
public func callAsFunction(_ data: Request) async throws -> Response {
return try await call(data)
}
Expand All @@ -174,7 +172,7 @@ private protocol StreamResponseProtocol {}
///
/// This can be used as the generic `Response` parameter to ``Callable`` to receive both the
/// yielded messages and final return value of the streaming callable function.
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 12.0, watchOS 8.0, *)
public enum StreamResponse<Message: Decodable & Sendable, Result: Decodable & Sendable>: Decodable,
Sendable,
StreamResponseProtocol {
Expand Down
46 changes: 1 addition & 45 deletions FirebaseFunctions/Sources/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ enum FunctionsConstants {
return URL(string: "https://\(region)-\(projectID).cloudfunctions.net/\(name)")
}

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

private func callFunction(url: URL,
withObject data: Any?,
options: HTTPSCallableOptions?,
timeout: TimeInterval,
context: FunctionsContext,
completion: @escaping @MainActor (Result<HTTPSCallableResult, Error>)
-> Void) {
let fetcher: GTMSessionFetcher
do {
fetcher = try makeFetcher(
url: url,
data: data,
options: options,
timeout: timeout,
context: context
)
} catch {
DispatchQueue.main.async {
completion(.failure(error))
}
return
}

fetcher.beginFetch { [self] data, error in
let result: Result<HTTPSCallableResult, any Error>
if let error {
result = .failure(processedError(fromResponseError: error, endpointURL: url))
} else if let data {
do {
result = try .success(callableResult(fromResponseData: data, endpointURL: url))
} catch {
result = .failure(error)
}
} else {
result = .failure(FunctionsError(.internal))
}

DispatchQueue.main.async {
completion(result)
}
}
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
func stream(at url: URL,
data: SendableWrapper?,
Expand Down Expand Up @@ -556,7 +512,7 @@ enum FunctionsConstants {
}
}

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@available(macOS 12.0, watchOS 8.0, *)
private func callableStreamResult(fromResponseData data: Data,
endpointURL url: URL) throws -> sending JSONStreamResponse {
let data = try processedData(fromResponseData: data, endpointURL: url)
Expand Down
1 change: 0 additions & 1 deletion FirebaseFunctions/Sources/HTTPSCallable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public final class HTTPSCallable: NSObject, Sendable {
/// - Parameter data: Parameters to pass to the trigger.
/// - Throws: An error if the Cloud Functions invocation failed.
/// - Returns: The result of the call.
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
public func call(_ data: Any? = nil) async throws -> sending HTTPSCallableResult {
try await functions
.callFunction(at: url, withObject: data, options: options, timeout: timeoutInterval)
Expand Down
3 changes: 0 additions & 3 deletions FirebaseFunctions/Sources/Internal/FunctionsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct FunctionsContextProvider: Sendable {
self.appCheck = appCheck
}

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

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

@available(iOS 13, macCatalyst 13, macOS 10.15, tvOS 13, watchOS 7, *)
private func getLimitedUseAppCheckToken(options: HTTPSCallableOptions?) async -> String? {
// At the moment, `await` doesn’t get along with Objective-C’s optional protocol methods.
await withCheckedContinuation { (continuation: CheckedContinuation<String?, Never>) in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class MockFunctions: Functions, @unchecked Sendable {
}
}

@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
class HTTPSCallableTests: XCTestCase {
func testCallWithoutParametersSuccess() {
// given
Expand Down
15 changes: 0 additions & 15 deletions FirebaseFunctions/Tests/Integration/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testDataAsync() async throws {
let data = DataTestRequest(
bool: true,
Expand Down Expand Up @@ -174,7 +173,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testScalarAsync() async throws {
let byName = functions.httpsCallable(
"scalarTest",
Expand All @@ -193,7 +191,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testScalarAsyncAlternateSignature() async throws {
let byName: Callable<Int16, Int> = functions.httpsCallable("scalarTest")
let byURL: Callable<Int16, Int> = functions.httpsCallable(emulatorURL("scalarTest"))
Expand Down Expand Up @@ -241,7 +238,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testTokenAsync() async throws {
// Recreate functions with a token.
let functions = Functions(
Expand Down Expand Up @@ -297,7 +293,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testFCMTokenAsync() async throws {
let byName = functions.httpsCallable(
"FCMTokenTest",
Expand Down Expand Up @@ -342,7 +337,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testNullAsync() async throws {
let byName = functions.httpsCallable(
"nullTest",
Expand Down Expand Up @@ -391,7 +385,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testMissingResultAsync() async {
let byName = functions.httpsCallable(
"missingResultTest",
Expand Down Expand Up @@ -441,11 +434,10 @@
XCTFail("Failed to throw error for missing result")
}
XCTAssert(true)
waitForExpectations(timeout: 5)

Check failure on line 437 in FirebaseFunctions/Tests/Integration/IntegrationTests.swift

View workflow job for this annotation

GitHub Actions / spm-integration (FirebaseFunctionsIntegration) / spm (macos-15, Xcode_16.4, iOS)

testUnhandledError, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "testUnhandledError()".
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testUnhandledErrorAsync() async {
let byName = functions.httpsCallable(
"unhandledErrorTest",
Expand Down Expand Up @@ -498,7 +490,6 @@
waitForExpectations(timeout: 5)
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testUnknownErrorAsync() async {
let byName = functions.httpsCallable(
"unknownErrorTest",
Expand Down Expand Up @@ -553,7 +544,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testExplicitErrorAsync() async {
let byName = functions.httpsCallable(
"explicitErrorTest",
Expand Down Expand Up @@ -604,11 +594,10 @@
}
XCTFail("Failed to throw error for missing result")
}
waitForExpectations(timeout: 5)

Check failure on line 597 in FirebaseFunctions/Tests/Integration/IntegrationTests.swift

View workflow job for this annotation

GitHub Actions / spm-integration (FirebaseFunctionsIntegration) / spm (macos-15, Xcode_16.4, iOS)

testHttpError, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "testHttpError()".

Check failure on line 597 in FirebaseFunctions/Tests/Integration/IntegrationTests.swift

View workflow job for this annotation

GitHub Actions / spm-integration (FirebaseFunctionsIntegration) / spm (macos-15, Xcode_16.4, iOS)

testHttpError, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "testHttpError()".
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testHttpErrorAsync() async {
let byName = functions.httpsCallable(
"httpErrorTest",
Expand Down Expand Up @@ -661,7 +650,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testThrowErrorAsync() async {
let byName = functions.httpsCallable(
"throwTest",
Expand Down Expand Up @@ -716,7 +704,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testTimeoutAsync() async {
var byName = functions.httpsCallable(
"timeoutTest",
Expand Down Expand Up @@ -778,7 +765,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testCallAsFunctionAsync() async throws {
let data = DataTestRequest(
bool: true,
Expand Down Expand Up @@ -841,7 +827,6 @@
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testInferredTyesAsync() async throws {
let data = DataTestRequest(
bool: true,
Expand Down Expand Up @@ -881,7 +866,7 @@
XCTAssert(Thread.isMainThread)
expectation.fulfill()
}
waitForExpectations(timeout: 5)

Check failure on line 869 in FirebaseFunctions/Tests/Integration/IntegrationTests.swift

View workflow job for this annotation

GitHub Actions / spm-integration (FirebaseFunctionsIntegration) / spm (macos-15, Xcode_16.4, iOS)

testFunctionsReturnsOnMainThread, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "testFunctionsReturnsOnMainThread()".
}

@MainActor func testFunctionsThrowsOnMainThread() {
Expand All @@ -897,7 +882,7 @@
XCTAssert(Thread.isMainThread)
expectation.fulfill()
}
waitForExpectations(timeout: 5)

Check failure on line 885 in FirebaseFunctions/Tests/Integration/IntegrationTests.swift

View workflow job for this annotation

GitHub Actions / spm-integration (FirebaseFunctionsIntegration) / spm (macos-15, Xcode_16.4, iOS)

testFunctionsThrowsOnMainThread, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "testFunctionsThrowsOnMainThread()".
}
}

Expand Down
32 changes: 13 additions & 19 deletions FirebaseFunctions/Tests/Unit/FunctionsAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,13 @@ final class FunctionsAPITests: XCTestCase {
}
}

if #available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
// async/await is a Swift Concurrency feature available on iOS 13+ and macOS 10.15+
Task {
do {
let data: Any? = nil
let result = try await callableRef.call(data)
_ = result.data
} catch {
// ...
}
Task {
do {
let data: Any? = nil
let result = try await callableRef.call(data)
_ = result.data
} catch {
// ...
}
}

Expand All @@ -106,15 +103,12 @@ final class FunctionsAPITests: XCTestCase {
}
}

if #available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 7.0, *) {
// async/await is a Swift Concurrency feature available on iOS 13+ and macOS 10.15+
Task {
do {
let result = try await callableRef.call()
_ = result.data
} catch {
// ...
}
Task {
do {
let result = try await callableRef.call()
_ = result.data
} catch {
// ...
}
}

Expand Down
Loading