-
Notifications
You must be signed in to change notification settings - Fork 18
Support deep type conversions in FirebaseFunctions data and add crashlytics log function #59
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
Conversation
|
|
||
| // MARK: - Kotlin to Swift type conversion helpers (from SkipFirebaseFirestore) | ||
|
|
||
| fileprivate func deepSwift(value: Any) -> Any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about harmonizing with SkipFirestore by moving its similar deepSwift implementation:
skip-firebase/Sources/SkipFirebaseFirestore/SkipFirebaseFirestore.swift
Lines 1107 to 1119 in 9b64623
| fileprivate func deepSwift(value: Any) -> Any { | |
| if let str = value as? String { | |
| return str // needed to not be treated as a Collection | |
| } else if let ts = value as? com.google.firebase.Timestamp { | |
| return Timestamp(timestamp: ts) | |
| } else if let map = value as? kotlin.collections.Map<Any, Any> { | |
| return deepSwift(map: map) | |
| } else if let collection = value as? kotlin.collections.Collection<Any> { | |
| return deepSwift(collection: collection) | |
| } else { | |
| return value | |
| } | |
| } |
... into SkipFirebaseCore.swift? That way we would share the same implementation for both Functions and Firestore…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it a try, hope I won't run into merge conflicts this time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to move Timestamp into Core then as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to move Timestamp into Core then as well
I think that's fine, since it is a core type for Firebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we somehow "reimport" this in skipfirestore? I noticed now to access Timestamps we need to import SkipFirebaseCore + skipfirebasefirestore for android, while only firestore for iOS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right … that is a problem. We don't currently handle @_exported import … imports, and so anything defined in SkipFirebaseCore won't come in automatically when importing the other two packages.
Maybe you could add a public typealias Timestamp = SkipFirebaseCore.Timestamp in each of SkipFirebaseFirestore.swift and SkipFirebaseFunction.swift to work around this for the time being?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…and if that does't work out, we can always just go back to duplicating the deepSwift logic in both packages.
| } | ||
| } | ||
|
|
||
| public func deepSwift<T>(map: kotlin.collections.Map<T, Any>) -> Dictionary<T, Any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think only the top deepSwift(value: Any) function needs to be public. These other ones can be private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course, fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, seeing a CI failure:
e: file:///Users/runner/work/skip-firebase/skip-firebase/.build/plugins/outputs/skip-firebase/SkipFirebaseFirestore/destination/skipstone/SkipFirebaseFirestore/src/main/kotlin/skip/firebase/firestore/SkipFirebaseFirestore.kt:1041:20 Cannot access 'fun <T> deepSwift(map: Map<T, Any>): Dictionary<T, Any>': it is private in file.
e: file:///Users/runner/work/skip-firebase/skip-firebase/.build/plugins/outputs/skip-firebase/SkipFirebaseFirestore/destination/skipstone/SkipFirebaseFirestore/src/main/kotlin/skip/firebase/firestore/SkipFirebaseFirestore.kt:1080:20 Cannot access 'fun <T> deepSwift(map: Map<T, Any>): Dictionary<T, Any>': it is private in file.
e: file:///Users/runner/work/skip-firebase/skip-firebase/.build/plugins/outputs/skip-firebase/SkipFirebaseFirestore/destination/skipstone/SkipFirebaseFirestore/src/main/kotlin/skip/firebase/firestore/SkipFirebaseFirestore.kt:1041:20 Cannot access 'fun <T> deepSwift(map: Map<T, Any>): Dictionary<T, Any>': it is private in file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, for e.g. in querydocumentsnapshot in skipfirestore we need
override public func data() -> [String: Any] {
if let data = doc.getData() {
return deepSwift(map: data)
} else {
return [:]
}
}
I'll make them internal, agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh it looks like Kotlin's internal might work file-level instead of module-scoped? I guess I have to revert to public, tests are failing with internal as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that'll be fine.
|
Thanks! One last request, can you add typealiases for That way, if anyone was relying on getting |
… in firestore, functions
|
Thanks for this! |
Thank you for contributing to the Skip project! Please use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.
Firestore test doesnt pass for Kotlin (12/11 passed) but I didnt touch Firestore
Skip Pull Request Checklist:
swift test