powersync-js icon indicating copy to clipboard operation
powersync-js copied to clipboard

[BUG] CrudEntry data type mismatch on uploadData connector

Open rossicler-hostalky opened this issue 7 months ago • 5 comments

Hi, I have created a common lib with a connector to upload the data to my API, but when using this in my React Native app, the transaction data is not matching the CrudEntry type. This is more or less what I have setup to test:

const transaction = await database.getNextCrudTransaction();
console.log("data", transaction.crud);

TypeScript says the type of transaction.crud is CrudEntry[], but this is what I get from the console.log: [{"data": [Object], "id": "67ebfcb34b14c2a8b140b4e5", "op": "PUT", "op_id": 4, "tx_id": 4, "type": "mytablename"}]

For this reason my upload is failing, due to expecting the data to be something like: "op is a CrudEntry"

const record = {
  table: op.table,
  id: op.id,
  op: op.op,
  data: op.opData,
};

rossicler-hostalky avatar Apr 01 '25 15:04 rossicler-hostalky

Hey @rossicler-hostalky can you provide some version of the SDK and it's dependencies please? This feels like an older implementation.

michaelbarnes avatar Apr 02 '25 23:04 michaelbarnes

Hey @rossicler-hostalky can you provide some version of the SDK and it's dependencies please? This feels like an older implementation.

These are some of the related dependencies on my react-native project:

"@powersync/react-native": "^1.19.0"
"@powersync/drizzle-driver": "^0.4.0"
"@journeyapps/react-native-quick-sqlite": "^2.4.2"
"drizzle-orm": "^0.40.1"

This is the dependencies on my common lib:

"@powersync/common": "^1.25.0"

I also tried remove the usage from my common lib to make sure that wasn't the problem, but the issue persisted.

rossicler-hostalky avatar Apr 03 '25 14:04 rossicler-hostalky

I'm seeing this as well:


    {
        "op_id": 337,
        "op": "PATCH",
        "type": "AccountTransaction",
        "id": "03df58aa-4cf4-44ee-ab58-0d48a4a232df",
        "tx_id": 279,
        "data": {
            "type": "INCOME"
        }
    },

been around for at least 9 months

  "name": "@powersync/common",
  "version": "1.31.1",

jasonlewicki avatar Jun 10 '25 04:06 jasonlewicki

I was able to reproduce the console.log statement printing a result in the form shown above, however when debugging and checking the keys of a CrudEntry I could confirm that the returned CrudEntry does satisfy the CrudEntry type.

My suspicion is that the React Native console.log call is executing the toJSON method on the CrudEntry before printing the log. This JSON object has the structure mentioned in the bug report.

See the debugger screenshot below which confirms the result object conforms to the CrudEntry type.

Image

stevensJourney avatar Jun 17 '25 08:06 stevensJourney

It might be at the latest version, but at the version I reported the issue it wasn't, as I confirmed that the data received in the backend was wrong. I created a parser in my backend connector that handles both formats, so I didn't had any problems after that.

private getRecord(op: CrudEntry | any) {
  return {
    table: op.table ?? op.type,
    id: op.id,
    op: op.op,
    data: op.opData ?? op.data,
  };
}

rossicler-hostalky avatar Jun 29 '25 17:06 rossicler-hostalky