pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.52k stars 1.06k forks source link

Firebase replication throwing error #4347

Closed ravi-poonia closed 1 year ago

ravi-poonia commented 1 year ago

RXDB version : 13.17.1

Firebase replication throws the following error:

RxError (RC_PULL): RxError (RC_PULL):
RxReplication pull handler threw an error - see .errors for more details
Given parameters: {
checkpoint:null
errors:[
  {
    "code": "invalid-argument",
    "customData": null,
    "name": "FirebaseError"
  }
]
direction:"pull"}
    at newRxError (/Users/ravipoonia/code/transport-js/node_modules/rxdb/src/rx-error.ts:107:12)
    at /Users/ravipoonia/code/transport-js/node_modules/rxdb/src/plugins/replication/index.ts:204:57
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'RC_PULL',
  parameters: {
    checkpoint: undefined,
    errors: [ [FirebaseError] ],
    direction: 'pull'
  },
  rxdb: true
}

As you can see, its impossible to figure out what the issue is from the above error message. Finally i was able to figure out something after trying out the test:replication-firestore test with real firebase config.

{
    "code": "RC_PULL",
    "parameters": {
        "checkpoint": {
            "id": "qbzieljdgnqt",
            "serverTimestamp": "2023-01-25T11:18:02.068Z"
        },
        "errors": [
            {
                "name": "FirebaseError",
                "message": "Order by clause cannot contain a field with an equality filter serverTimestamp",
                "code": "invalid-argument",
                "stack": "FirebaseError: Order by clause cannot contain a field with an equality filter serverTimestamp"
            }
        ],
        "direction": "pull"
    },
    "rxdb": true
}

After digging some more into it, I think the culprit is this line https://github.com/pubkey/rxdb/blob/7607a8b9b2346f5de962eac9d2e04045a36d599c/src/plugins/replication-firestore/index.ts#L135

After this also it kept throwing some errors about indexes, I'm not sure about those. I'll have to look into it some more, but the above mentioned is a sure issue.

pubkey commented 1 year ago

The firestore dev mock does not support the changestream, so this is not testable in the CI. Also I do not have a firebase account atm, so please make a PR with a proposed fix.

ravi-poonia commented 1 year ago

I made the change and it seems to be working, but the index issue I reported earlier is still there, Firebase requires us to create one-time indexes which it informs us by throwing an error, but the weird thing is, the msg from that error is not shown in console, so I made a change in the error parse method, I think this should fix it.

@pubkey I want to push these changes against the v13 as I'm using that one right now, can you let me know against which branch should I create the PR?

Changes

pubkey commented 1 year ago

Please make a PR against the latest master. There will be no more v13 release.

ravi-poonia commented 1 year ago

I can't migrate to v14 right now, I'm currently using the leveldown with pouchDB, so it's a huge change to migrate to v14, can you provide any suggestion.

pubkey commented 1 year ago

You can fork the repo at the v13 tag and patch your fork

ravi-poonia commented 1 year ago

The 13.17.1 tag is at the wrong commit btw, can you pls update it, Thanks

pubkey commented 1 year ago

Closing this. Please make a PR.