react-native-onyx 3.0.41 → 3.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -86,7 +86,7 @@ const provider = {
86
86
  if (!provider.store) {
87
87
  throw new Error('Store is not initialized!');
88
88
  }
89
- const query = 'REPLACE INTO keyvaluepairs (record_key, valueJSON) VALUES (?, json(?));';
89
+ const query = 'REPLACE INTO keyvaluepairs (record_key, valueJSON) VALUES (?, ?);';
90
90
  const params = pairs.map((pair) => [pair[0], JSON.stringify(pair[1] === undefined ? null : pair[1])]);
91
91
  if (utils_1.default.isEmptyObject(params)) {
92
92
  return Promise.resolve();
@@ -100,12 +100,16 @@ const provider = {
100
100
  const commands = [];
101
101
  // Query to merge the change into the DB value.
102
102
  const patchQuery = `INSERT INTO keyvaluepairs (record_key, valueJSON)
103
- VALUES (:key, JSON(:value))
103
+ VALUES (:key, :value)
104
104
  ON CONFLICT DO UPDATE
105
- SET valueJSON = JSON_PATCH(valueJSON, JSON(:value));
105
+ SET valueJSON = JSON_PATCH(valueJSON, :value);
106
106
  `;
107
107
  const patchQueryArguments = [];
108
108
  // Query to fully replace the nested objects of the DB value.
109
+ // NOTE: The JSON() wrapper around the replacement value is required here. Unlike JSON_PATCH (which
110
+ // parses both arguments as JSON internally), JSON_REPLACE treats a plain TEXT binding as a quoted
111
+ // JSON string. Without JSON(), objects would be stored as string values (e.g. "{...}") instead of
112
+ // actual JSON objects, corrupting the stored data.
109
113
  const replaceQuery = `UPDATE keyvaluepairs
110
114
  SET valueJSON = JSON_REPLACE(valueJSON, ?, JSON(?))
111
115
  WHERE record_key = ?;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.41",
3
+ "version": "3.0.42",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",