Skip to content
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

Fix error when replication ids include hyphens #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jmacindoe
Copy link
Contributor

Hey, awesome project! It works great but I came across two bugs while using it so I'm putting up PRs for them. For this PR, I'm getting an error if there are hyphens in my replication identifier:

Error: malformatted revision: 1-rxdbreplicationmy-id
    at parseRevision (webpack-internal:///../../node_modules/rxdb/dist/es/plugins/utils/utils-revision.js:10:11)
    at createRevision (webpack-internal:///../../node_modules/rxdb/dist/es/plugins/utils/utils-revision.js:31:51)
    at getMetaWriteRow (webpack-internal:///../../node_modules/rxdb/dist/es/replication-protocol/meta-instance.js:98:80)
    at eval (webpack-internal:///../../node_modules/rxdb/dist/es/replication-protocol/upstream.js:199:97)
    at async Promise.all (index 0)
    at async eval (webpack-internal:///../../node_modules/rxdb/dist/es/replication-protocol/upstream.js:168:7)

Looking at the rxdb source code, it looks like we're meant to pass a hash of the id to super() rather than the id itself https://github.com/pubkey/rxdb/blob/a73c91add858097ca4138009e52531a21eb76ec8/src/plugins/replication/index.ts#L88. An example usage from the rxdb code is here which I based this PR on https://github.com/pubkey/rxdb/blob/a73c91add858097ca4138009e52531a21eb76ec8/src/plugins/replication/index.ts#LL461C13-L461C13

@jmacindoe
Copy link
Contributor Author

Also FYI the integration tests are failing on main so they also fail on this branch

@marceljuenemann
Copy link
Owner

Good catch! Didn't realize this as I based my code mostly on the Firebase replication, which just passes the hash through.

Unfortunately, changing the hash means that existing replications become invalid, i.e. the code will refect the entire table. So I guess I'll have to change the major version for this.

@marceljuenemann
Copy link
Owner

I've been thinking about this, don't think it's worth making a breaking change just to be able to use hyphens. The caller could do the hashing or just make sure there are no hyphens in the replication ID.

I'll probably update the documentation and make this change only when there is another reason to do a breaking release

@marceljuenemann marceljuenemann added this to the v2 milestone Oct 3, 2023
@tg44
Copy link

tg44 commented Jul 4, 2024

Why don't we hash only if we have hypens in it? Then we keep the original functionality and fix the hypen issue with one stone...

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.

3 participants