New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: Add support for Swift object serialization in Cloud Functions #8528
Comments
@EthanLozano Thanks for the Feature Request. My preference would be an implementation in a new FirebaseFunctionsSwift library comparable to the Codable implementation for Firestore and the Codable implementation in FirebaseDatabaseSwift added in #6568. |
I just saw this issue referenced and wanted to chime in: Wrt code size I guess it would be silly to have yet another copy of encoder/decoder for so similar a purpose. On the other hand it adds to the complexity of the project to split out the encoder / decoder into their own package. Which solution would the Firebase team prefer? Another copy or trying to split up the project into another module? |
@mortenbekditlevsen Good point! We definitely don't want to repeat code, so my preference would be to factor into another module. In Swift Package Manager, it could be a target, but not a product. |
I'd like to help implementing that refactor, but I have a few questions: Note: A long time ago on the swift forums I've been suggesting that |
Paging @schmidt-sebastian to get Firestore's perspective. |
Quick comment regarding Firestore: I'd personally love to have the key coding strategies available here too. :-) |
I like the We still need CocoaPods, but we can defer the details. I could either provide guidance or set it up reasonably quickly once the SPM implementation is done. |
Excellent, thanks for your comments. https://forums.swift.org/t/idea-exposing-jsonencoder-and-jsondecoder-functionality/6379 https://forums.swift.org/t/revisiting-structureencoder-and-structuredecoder/12634 |
I created a PR that moves the encoder/decoder pair into a new target. Next I'll have a look at the requested functionality itself. |
With regards to Firestore's encoding and decoding: I think that most of what is done in the FirestoreDecoder could in fact be moved out of the decoder and replaced by a concept, that is perhaps a bit more generic and would be ok to have in the If we create a protocol:
(line 337 of FirestoreDecoder.swift) I think that the actual logic of adding a Another thing that happens in the
instead of:
That would basically mean: If something in the encoded structure can be cast directly to the value that we are parsing, we just do so and return it. It sounds to me like it would work, but of course it could be guarded by a protocol conformance check in order to play it safe... Then there is the unboxing of All in all I think there might be big gains to sharing encoder and decoder - and have the same 'strategies' available. And also keeping the encoder and decoder easily 'upgradable' when new functionality is added to |
Another thought about FirestoreDecoder.swift: Regarding the throwing that happens at line 349 when the key that is attempted to be decoded exists in the encoded structure. This makes it very hard to evolve your model from either: going from an actual I get that the intention is to avoid the confusion about where the value actually comes from, but otherwise in the decoding world we usually don't care about anything in the encoded structure that we are not using for decoding... Should I raise this concern as a separate issue? |
Now there's also also a PR (#8854) attempting to solve this actual issue. |
And to explore merging the I intentionally left out the check for presence of the key elsewhere in the encoded structure based on my comment about model evolution above. I couldn't make All remaining 'work' that was before in |
Yep the FirestoreSwift tests have a nested dependency on the C++ gtest framework which would be challenging to port to Swift Package Manager. It might be worth investigating if we could have pure Swift tests for the Firestore Swift tests. cc: @schmidt-sebastian @wu-hui |
I am not opposed to adding Swift only tests if this unblocks this effort. |
Closing now that #8854 has merged to master |
Please add Swift Codable support to Cloud Functions in a FirebaseFunctionsSwift module (or within FirebaseCombineSwift). This request is similar to #627 except for Cloud Functions rather than for Firestore.
More specifically, please add Encodable support when calling a function:
Similarly, please add Decodable support to the function result:
The text was updated successfully, but these errors were encountered: