FirebaseFirestore improvements#80
Open
IT-Guy007 wants to merge 3 commits into
Open
Conversation
SkipFirebaseCore.swift - Timestamp now conforms to Codable using internal sentinel keys (__fts__/__ftn__) for JSON round-tripping SkipFirebaseFirestore.swift - GeoPoint class — Hashable, KotlinConverting (so it survives .kotlin() dict conversion), Codable - firestoreDeepSwift — replaces deepSwift calls throughout to also handle com.google.firebase.firestore.GeoPoint → GeoPoint - FirestoreCacheSizeUnlimited, FirestoreCacheSettings, MemoryGarbageCollectionSettings, MemoryLRUGCSettings, MemoryEagerGCSettings, MemoryCacheSettings, PersistentCacheSettings - FirestoreSettings class with host, isSSLEnabled, cacheSettings and toAndroid() builder - Firestore.settings get/set property — applies to the Android store on set - SnapshotMetadata.isFromCache - DocumentSnapshot.metadata, .reference, .get(_ fieldPath: FieldPath), .data<T>() throws -> T - DocumentReference.getDocument(source:) async, setData(_:mergeFields:) async, setData<T: Encodable>(from:merge:) async, setData<T: Encodable>(from:mergeFields:) async - CollectionReference.addDocument(data:completion:) - FirestoreEncoder and FirestoreDecoder classes One API note: Skip can't bridge T.Type parameters, so on Android the Codable decode is let m: MyModel = try snapshot.data() (return-type inference). On iOS you use FirebaseFirestoreSwift's snapshot.data(as: MyModel.self) as normal. The encode direction (setData(from:)) works identically on both platforms.
Contributor
Author
|
Just figured out that there are more methods that I need to support, converted to draft |
SkipFirebaseCore.swift
- Timestamp.init(from:) now handles a plain Double (seconds since epoch) in addition to the existing {"__fts__"/"__ftn__"} sentinel dict — enables Timestamp fields in Codable
models to decode from the timeInterval doubles emitted by the new decoder path
SkipFirebaseFirestore.swift
Property wrappers (new):
- @documentid<Value: Codable> — no-op on encode; on decode reads from decoder.userInfo[.firestoreDocumentID] (set by the decoder when a documentID is provided), with a
keyed-container fallback for Skip runtimes where userInfo may not propagate
- @ServerTimestamp — on encode: nil → {"__fts_server__": true} sentinel (restored to FieldValue.serverTimestamp() by the encoder pass); non-nil → actual Timestamp. On decode: reads
Timestamp back normally
- CodingUserInfoKey.firestoreDocumentID extension
- _DocumentIDCodingKey and _FirestoreDateSentinelKeys private enum helpers
FirestoreEncoder improvements:
- Date → {"__firestore_date__": timeInterval} sentinel via custom dateEncodingStrategy, restored to Timestamp in restoreFirestoreTypes
- {"__fts_server__": true} → FieldValue.serverTimestamp() in restoreFirestoreTypes
- NSNumber Bool coercion in restoreFirestoreTypes (Android JSONSerialization returns 0/1 instead of native Bool)
FirestoreDecoder improvements:
- New decode(from:documentID:) overload — injects document ID into userInfo, sets dateDecodingStrategy = .secondsSince1970
- prepareForJSON now converts Timestamp → Double (timeInterval) instead of sentinel dict, enabling both Date and Timestamp model fields to decode correctly
- NSNumber Bool coercion in prepareForJSON
- DocumentSnapshot.decoded() now passes documentID to the decoder
New Codable overloads:
- CollectionReference.addDocument(from: T) async throws
- WriteBatch.setData(from: T, forDocument:) throws → WriteBatch (chainable)
- WriteBatch.setData(from: T, forDocument:mergeFields:) throws → WriteBatch
Remove Codable from the main class declarations for Timestamp and GeoPoint and add separate extension-based Codable conformance. This prevents the Skip bridge generator from including Codable in the generated bridge class (which has a JObject peer that cannot auto-synthesize Codable); the existing encode/decode implementations already satisfy the conformance. Changes made in SkipFirebaseCore.swift and SkipFirebaseFirestore.swift.
Contributor
Author
|
Codable gave issues, moved to extension implementation |
Contributor
Author
|
Ready for review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SkipFirebaseCore.swift
SkipFirebaseFirestore.swift
One API note: Skip can't bridge T.Type parameters, so on Android the Codable decode is let m: MyModel = try snapshot.data() (return-type inference). On iOS you use FirebaseFirestoreSwift's snapshot.data(as:
MyModel.self) as normal. The encode direction (setData(from:)) works identically on both platforms.
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.
Please review the contribution guide at https://skip.dev/docs/contributing/ for advice and guidance on making high-quality PRs.
Skip Pull Request Checklist:
swift testAI was used for documentation writes and codable implementation