Skip to content

Report DataSync object type on subscribe events - #267

Merged
jguz-pubnub merged 5 commits into
feat/data-syncfrom
feat/swift-data-sync-fixes
Oct 8, 2026
Merged

jguz-pubnub merged 5 commits into
feat/data-syncfrom
feat/swift-data-sync-fixes

Conversation

@jguz-pubnub

@jguz-pubnub jguz-pubnub commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

No description provided.

@pubnub pubnub deleted a comment from coderabbitai Bot Oct 5, 2026
@jguz-pubnub
jguz-pubnub force-pushed the feat/swift-data-sync-fixes branch 2 times, most recently from 943e1b1 to f9bcdbf Compare October 5, 2026 16:32
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
@jguz-pubnub
jguz-pubnub force-pushed the feat/swift-data-sync-fixes branch from f9bcdbf to 6499540 Compare October 6, 2026 08:51
// MARK: - KMPDataSyncEvent

@objc
public class KMPDataSyncEvent: NSObject {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add:
channel , timetoken,
and optionally
subscription, publisher, userMetadata
?

The thing is that in Kotlin they are present.

@jguz-pubnub jguz-pubnub Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you not drop source and version ? kotlin has them

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, could you add to PubNubDataSyncRelationship and PubNubDataSyncRemovedRelationship
classLevel: PubNubDataSyncClassLevel
and pass the decoded classLevel to them?

@jguz-pubnub jguz-pubnub Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jguz-pubnub jguz-pubnub Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add PubNubDataSyncUnknownEvent and let you know when it's ready

@pubnub pubnub deleted a comment from coderabbitai Bot Oct 6, 2026
@pubnub pubnub deleted a comment from coderabbitai Bot Oct 6, 2026
@pubnub pubnub deleted a comment from coderabbitai Bot Oct 6, 2026
@pubnub pubnub deleted a comment from coderabbitai Bot Oct 7, 2026
@pubnub pubnub deleted a comment from coderabbitai Bot Oct 8, 2026
@jguz-pubnub
jguz-pubnub merged commit 39a67be into feat/data-sync Oct 8, 2026
18 of 19 checks passed
@jguz-pubnub
jguz-pubnub deleted the feat/swift-data-sync-fixes branch October 8, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants