Skip to content

Commit 8cb165b

Browse files
Added tests for Firebase Functions Swift overlay. Added doc comments. Test target is only currently added to SwiftPM
1 parent 2f1c7ae commit 8cb165b

File tree

3 files changed

+599
-3
lines changed

3 files changed

+599
-3
lines changed

FirebaseFunctionsSwift/Sources/Codable/Callable+Codable.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ import FirebaseFunctions
1919
import FirebaseSharedSwift
2020

2121
public extension Functions {
22+
/**
23+
* Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
24+
* request and the type of a `Decodable` response.
25+
*
26+
* - Parameter name: The name of the Callable HTTPS trigger
27+
* - Parameter requestType: The type of the `Encodable` entity to use for requests to this `Callable`
28+
* - Parameter responseType: The type of the `Decodable` entity to use for responses from this `Callable`
29+
*/
2230
func httpsCallable<Request: Encodable,
2331
Response: Decodable>(_ name: String,
2432
requestType: Request.Type,
@@ -28,7 +36,22 @@ public extension Functions {
2836
}
2937
}
3038

39+
/**
40+
* A `Callable` is reference to a particular Callable HTTPS trigger in Cloud Functions.
41+
*/
3142
public struct Callable<Request: Encodable, Response: Decodable> {
43+
/**
44+
* The timeout to use when calling the function. Defaults to 60 seconds.
45+
*/
46+
public var timeoutInterval: TimeInterval {
47+
get {
48+
callable.timeoutInterval
49+
}
50+
set {
51+
callable.timeoutInterval = newValue
52+
}
53+
}
54+
3255
enum CallableError: Error {
3356
case internalError
3457
}
@@ -38,12 +61,31 @@ public struct Callable<Request: Encodable, Response: Decodable> {
3861
self.callable = callable
3962
}
4063

64+
/**
65+
* Executes this Callable HTTPS trigger asynchronously.
66+
*
67+
* The data passed into the trigger must be of the generic `Request` type:
68+
*
69+
* The request to the Cloud Functions backend made by this method automatically includes a
70+
* Firebase Instance ID token to identify the app instance. If a user is logged in with Firebase
71+
* Auth, an auth ID token for the user is also automatically included.
72+
*
73+
* Firebase Instance ID sends data to the Firebase backend periodically to collect information
74+
* regarding the app instance. To stop this, see `[FIRInstanceID deleteIDWithHandler:]`. It
75+
* resumes with a new Instance ID the next time you call this method.
76+
*
77+
* - Parameter data: Parameters to pass to the trigger.
78+
* - Parameter completion: The block to call when the HTTPS request has completed.
79+
*
80+
* - Throws: An error if any value throws an error during encoding.
81+
*/
4182
public func call(_ data: Request,
4283
encoder: StructureEncoder = StructureEncoder(),
4384
decoder: StructureDecoder = StructureDecoder(),
4485
completion: @escaping (Result<Response, Error>)
4586
-> Void) throws {
4687
let encoded = try encoder.encode(data)
88+
4789
callable.call(encoded) { result, error in
4890
do {
4991
if let result = result {
@@ -61,6 +103,27 @@ public struct Callable<Request: Encodable, Response: Decodable> {
61103
}
62104

63105
#if compiler(>=5.5) && canImport(_Concurrency)
106+
/**
107+
* Executes this Callable HTTPS trigger asynchronously.
108+
*
109+
* The data passed into the trigger must be of the generic `Request` type:
110+
*
111+
* The request to the Cloud Functions backend made by this method automatically includes a
112+
* Firebase Instance ID token to identify the app instance. If a user is logged in with Firebase
113+
* Auth, an auth ID token for the user is also automatically included.
114+
*
115+
* Firebase Instance ID sends data to the Firebase backend periodically to collect information
116+
* regarding the app instance. To stop this, see `[FIRInstanceID deleteIDWithHandler:]`. It
117+
* resumes with a new Instance ID the next time you call this method.
118+
*
119+
* - Parameter data: The `Request` representing the data to pass to the trigger.
120+
*
121+
* - Throws: An error if any value throws an error during encoding.
122+
* - Throws: An error if any value throws an error during decoding.
123+
* - Throws: An error if the callable fails to complete
124+
*
125+
* - Returns: The decoded `Response` value
126+
*/
64127
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
65128
public func call(_ data: Request,
66129
encoder: StructureEncoder = StructureEncoder(),

0 commit comments

Comments
 (0)