rxdb icon indicating copy to clipboard operation
rxdb copied to clipboard

fix(datapath) must be equivalent for pull and push

Open jwallet opened this issue 1 year ago • 3 comments

This PR contains:

  • IMPROVED DOCS
  • IMPROVED TESTS
  • A BUGFIX
  • BREAKING

Describe the problem you have without this PR

If we define a custom dataPath for the graphQL replication, we end up setting a different datapath for the pull and push rep. Pull rep does not handle the data. prefix while push already handles it with result.data

I changed this to make both (pull and push) use the same function helper to extract the proper datapath if defined or not by the user.

Based on the unit tests, I found some that were testing only the pull replication and needed data as a prefix so I made the helper function the same as the current pull.dataPath, so it will request the user to add data. as a prefix, if you prefer the other way around, let me know. However, it makes sense if for any reason the default selector ['data', Object.keys(result.data)[0])] doesn't work because there is no data key returned from the server (exceptional edge case, maybe they used the customFetch property) and it breaks the default selector on Object.keys(result.data)

I also changed the typing of dataPath to accept string[] since getProperty also accepts it.

{
  dataPath: ['data', 'foo', 'bar']
}
  // or
{
  dataPath: 'data.foo.bar'
}

jwallet avatar May 17 '24 13:05 jwallet

Is this a breaking change?

pubkey avatar May 17 '24 15:05 pubkey

Yes it is for the push replication. If someone used dataPath: 'pushNotifications' he will need to change it to 'data.pushNotifications'. Just like the pull dataPath.

jwallet avatar May 17 '24 22:05 jwallet

Ok that makes it complicated. At the moment there is no major release planned. I added the 16.0.0 label so it will be merged, but this will take a while.

pubkey avatar May 18 '24 11:05 pubkey