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

Rolling back some of PR #3356 #3436

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ x.x.x Release notes (yyyy-MM-dd)

### Fixed
* Fixed an issue in `toJSON()`, in combination with primaryKeys, where data from another table could be returned. ([#3331](https://github.com/realm/realm-js/issues/3331), since v10.0.0)
* Fixed an issue in `toJSON()` where `data` would output as `{}`, it now returns the data base64 encoded. ([#3356](https://github.com/realm/realm-js/pull/3356), since v10.0.0)
* TS: `RealmInsertionModel<T>` used in `realm.create<T>(...)` now ignores functions on Class Models. ([#3421](https://github.com/realm/realm-js/pull/3421), since v10.0.0)

### Compatibility
Expand Down
16 changes: 5 additions & 11 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,13 @@ module.exports = function(realmConstructor, context) {

// skip any functions & constructors (in case of class models).
if (typeof value === "function") {
return; // continue
return; // continue
}

if (value instanceof realmConstructor.Object || value instanceof realmConstructor.Collection) {
// recursively trigger `toJSON` for Realm instances with the same cache.
result[key] = value.toJSON(key, cache);
} else if (value instanceof ArrayBuffer) {
// convert "data" to base64 strings.
result[key] = Buffer.from(value).toString("base64");
} else {
// default to original value.
result[key] = value;
}
// recursively trigger `toJSON` for Realm instances with the same cache.
result[key] = (value instanceof realmConstructor.Object || value instanceof realmConstructor.Collection)
? value.toJSON(key, cache)
: value;
});

return result;
Expand Down