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

RJS-2765: Attempt to upgrade bson to v6 #6762

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 3 additions & 3 deletions integration-tests/tests/src/tests/linking-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,19 @@ describe("Linking objects", () => {
// Create a manufacturer with 2 cars.
this.realm.write(() => {
const sentra = this.realm.create(Car, {
_id: new Realm.BSON.ObjectID(),
_id: new Realm.BSON.ObjectId(),
model: "Sentra",
miles: 1000,
});

const pathfinder = this.realm.create(Car, {
_id: new Realm.BSON.ObjectID(),
_id: new Realm.BSON.ObjectId(),
model: "Pathfinder",
miles: 500,
});

this.realm.create(Manufacturer, {
_id: new Realm.BSON.ObjectID(),
_id: new Realm.BSON.ObjectId(),
name: "Nissan",
cars: [sentra, pathfinder],
});
Expand Down
117 changes: 50 additions & 67 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@react-native/eslint-config": "0.74.83",
"@react-native/eslint-plugin": "0.74.83",
"@react-native/typescript-config": "0.74.83",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/realm-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"license": "Apache-2.0",
"dependencies": {
"@realm/common": "^0.1.4",
"bson": "^4.5.4",
"bson": "^6.7.0",
"detect-browser": "^5.2.1",
"js-base64": "^3.7.6"
},
Expand Down
13 changes: 13 additions & 0 deletions packages/realm-web/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
//
////////////////////////////////////////////////////////////////////////////

import alias from "@rollup/plugin-alias";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import nodeResolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import dts from "rollup-plugin-dts";

import { createRequire } from "node:module";
const require = createRequire(import.meta.url);

import pkg from "./package.json" assert { type: "json" };

const replacer = replace({
Expand Down Expand Up @@ -97,6 +101,15 @@ export default [
},
],
plugins: [
// Providing an alias for the "bson" package to pick the CJS bundle over ESM
alias({
entries: [
{
find: "bson",
replacement: require.resolve("bson"),
},
],
}),
commonjs(),
typescript({
tsconfig: "src/dom/tsconfig.json",
Expand Down
6 changes: 3 additions & 3 deletions packages/realm-web/src/tests/MongoDBService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
////////////////////////////////////////////////////////////////////////////

import { expect } from "chai";
import { ObjectID } from "bson";
import { ObjectId } from "bson";

import { createService } from "../services/MongoDBService";

Expand Down Expand Up @@ -54,7 +54,7 @@ describe("MongoDB Remote service", () => {
.collection<MyDocument>("my-collection")
.find(
{
_id: ObjectID.createFromHexString("deadbeefdeadbeefdeadbeef"),
_id: ObjectId.createFromHexString("deadbeefdeadbeefdeadbeef"),
},
{ limit: 10 },
);
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("MongoDB Remote service", () => {
.collection<MyDocument>("my-collection")
.findOne(
{
_id: ObjectID.createFromHexString("deadbeefdeadbeefdeadbeef"),
_id: ObjectId.createFromHexString("deadbeefdeadbeefdeadbeef"),
},
{
projection: { name: 1 },
Expand Down
4 changes: 3 additions & 1 deletion packages/realm-web/src/utils/ejson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export function serialize<Obj extends SimpleObject>(obj: Obj): SimpleObject {
* @param obj The object or array of objects in extended-JSON format.
* @returns The object or array of objects with inflated BSON types.
*/
export function deserialize(obj: SimpleObject | SimpleObject[]): EJSON.SerializableTypes {
export function deserialize(
obj: SimpleObject | SimpleObject[],
): unknown /* Return type of 'ReturnType<typeof EJSON.deserialize>' is 'any' */ {
if (Array.isArray(obj)) {
return obj.map((doc) => EJSON.deserialize(doc));
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
},
"dependencies": {
"@realm/fetch": "^0.1.1",
"bson": "^4.7.2",
"bson": "^6.7.0",
"debug": "^4.3.4",
"node-machine-id": "^1.1.12",
"path-browserify": "^1.0.1",
Expand Down Expand Up @@ -357,4 +357,4 @@
6
]
}
}
}
2 changes: 0 additions & 2 deletions packages/realm/src/bson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import * as bson from "bson";
export namespace BSON {
export const ObjectId = bson.ObjectId;
export type ObjectId = bson.ObjectId;
export const ObjectID = bson.ObjectID;
export type ObjectID = bson.ObjectID;
export const Decimal128 = bson.Decimal128;
export type Decimal128 = bson.Decimal128;
export const UUID = bson.UUID;
Expand Down
Loading