Repository navigation
Report DataSync object type on subscribe events - #267
Conversation
943e1b1 to
f9bcdbf
Compare
Subscribe events now surface the DataSync object type from `metadata.type`, and unsupported DataSync envelopes are dropped instead of degrading to a message. - Add `PubNubDataSyncEntityKind` and `PubNubDataSyncRelationshipKind` - DataSync cases carry event structs exposing `kind` alongside the payload - Rename `PubNubDataSyncRemovedObject` to `PubNubDataSyncRemovedEntity` - Make `asPubNubEvent()` optional and drop undecodable DataSync envelopes
f9bcdbf to
6499540
Compare
| // MARK: - KMPDataSyncEvent | ||
|
|
||
| @objc | ||
| public class KMPDataSyncEvent: NSObject { |
There was a problem hiding this comment.
Would it be possible to add:
channel , timetoken,
and optionally
subscription, publisher, userMetadata
?
The thing is that in Kotlin they are present.
There was a problem hiding this comment.
I can add channel, timetoken, and subscription fields. There's no i field in a subscribe response for DataSync events, so publisher will always be empty. The last one from your list (userMetadata) is related to the old AppContext and shouldn't be advertised in DataSync events
| func asDataSyncEvent() -> PubNubDataSyncEvent? { | ||
| try? payload.decode(SubscribeDataSyncPayload.self).event | ||
| func decodeDataSyncEvent() throws -> PubNubDataSyncEvent { | ||
| try payload.decode(SubscribeDataSyncPayload.self).event |
There was a problem hiding this comment.
Could you not drop source and version ? kotlin has them
There was a problem hiding this comment.
As of now, even in AppContext, these fields are empty. This is because the Swift SDK was intentionally designed to hide low-level transport details. This is the right approach, in my opinion. I don't see any meaningful logic you can perform on fields like source and version.
I realize we won't be able to remove those fields from the Kotlin SDK. What I recommend is always setting these fields to empty strings when mapping to Kotlin events.
| @@ -135,18 +135,30 @@ listener.didReceiveBatchSubscription = { events in | |||
|
|
|||
| case .dataSyncChanged(let dataSyncEvent): | |||
There was a problem hiding this comment.
Please, could you add to PubNubDataSyncRelationship and PubNubDataSyncRemovedRelationship
classLevel: PubNubDataSyncClassLevel
and pass the decoded classLevel to them?
There was a problem hiding this comment.
Relationship classes are not possible for extensions. This is the reason why there's no classLevel property in PubNubDataSyncRemovedRelationship and PubNubDataSyncRelationship. Am I missing something crucial here?
There was a problem hiding this comment.
They are not present in CRUD operation but present in subscribe event. Currently for Membership it is "Global " and for Relationships it is "SubKey". But never mind we can handle this. The thing is that Kotlin and JS already have it.
There was a problem hiding this comment.
Ok, then I'll add it to
| case let .entityCreated(entity): | ||
| print("Data Sync entity created: \(entity.id)") | ||
| case let .entityUpdated(entity): | ||
| print("Data Sync entity updated: \(entity.id)") |
There was a problem hiding this comment.
This comment is not related to this file.
JVM and JS deliver a valid DataSync event with an unrecognised metadata.event or metadata.type as PNUnknownDataSyncEventMessage. Could you add this?
Unknown result: the payload is a DataSync event (metadata.source == "data-sync", and metadata.event and metadata.type are present non-empty strings), but the pair isn't one Swift
handles. Examples: type: "space", or event: "expire" on type: "user".
Keep dropping: the pair is known but the payload is broken, e.g. a required data field is missing. JVM drops these too, so behaviour matches.
There was a problem hiding this comment.
I'll take a look at that
There was a problem hiding this comment.
I will add PubNubDataSyncUnknownEvent and let you know when it's ready
No description provided.