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: Upgrade BSON #6593

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
> [!NOTE]
> This version communicates with Atlas Device Services through a different URL (https://services.cloud.mongodb.com). While we consider this an internal detail of the SDK, you might need to update rules in firewalls or other configuration that you've used to limit connections made by your app.

### Breaking changes
* The re-exported [bson](https://www.npmjs.com/package/bson) library (via `Realm.BSON`) has been upgraded from 4.7.2 to 6.6.0. ([6561](https://github.com/realm/realm-js/issues/6561))
* Notable changes (refer to BSON's [v5](https://github.com/mongodb/js-bson/releases/tag/v5.0.0) and [v6](https://github.com/mongodb/js-bson/releases/tag/v6.0.0) release notes for all changes):
* Removed `ObjectID` with uppercase `D` (please use `ObjectId`).
* `EJSON` is only exported as the value and not the type (to use it as a type, please use `typeof EJSON`).
* The `Decimal128.bytes` type is now a `Uint8Array` instead of a `Buffer`.

### Enhancements
* Updated bundled OpenSSL version to 3.2.0. ([realm/realm-core#7303](https://github.com/realm/realm-core/pull/7303))
* Improved performance of object notifiers with complex schemas by ~20%. ([realm/realm-core#7424](https://github.com/realm/realm-core/pull/7424))
Expand Down
12 changes: 6 additions & 6 deletions install-tests/test-runners/jest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
4 changes: 3 additions & 1 deletion integration-tests/tests/src/tests/sync/mixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ function describeTypes(flexibleSync: boolean) {
describeRoundtrip({
typeName: "Decimal128",
value: decimal128,
testValue: (value: Realm.BSON.Decimal128) => decimal128.bytes.equals(value.bytes),
testValue: (value: Realm.BSON.Decimal128) => {
expect(value.toString()).equals(decimal128.toString());
},
flexibleSync,
});

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/src/tests/sync/mongo-db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ describe("MongoDB Client", function () {
await insertThreeDocuments(this.collection);

const oldDoc = await this.collection.findOneAndDelete();
expect(oldDoc).to.deep.equal({ _id: insertedId3, text: insertedText, date: insertedDate });
expect(oldDoc).to.deep.equal({ _id: insertedId1, text: insertedText, date: insertedDate });

await expectToNotFindDoc(this.collection, { _id: insertedId1 }, { expectedCount: 2 });
});
Expand Down
48 changes: 38 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
],
"dependencies": {
"@react-native/eslint-config": "0.73.2",
"@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-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"html-webpack-plugin": "^5.5.0",
"mongodb-realm-cli": "^1.3.2",
"source-map-loader": "^5.0.0",
"ts-loader": "^9.3.0",
"ts-loader": "^9.5.1",
"webpack-cli": "^5.1.4"
}
}
24 changes: 12 additions & 12 deletions packages/realm-web-integration-tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ if (location.pathname.endsWith("-callback")) {
Realm.handleAuthRedirect();
} else if (location.pathname.endsWith("/google-login")) {
console.log("Hello to Google Login ...");
require("./google-login");
await import("./google-login");
} else {
new MochaRemoteClient({
tests: () => {
async tests() {
beforeEach(function () {
this.slow(1000);
this.timeout(10000);
});

require("./environment.test");
require("./app.test");
require("./credentials.test");
require("./user.test");
require("./functions.test");
require("./services.test");
require("./api-key-auth.test");
require("./email-password-auth.test");
require("./iife.test");
require("./bson.test");
await import("./environment.test");
await import("./app.test");
await import("./credentials.test");
await import("./user.test");
await import("./functions.test");
await import("./services.test");
await import("./api-key-auth.test");
await import("./email-password-auth.test");
await import("./iife.test");
await import("./bson.test");
},
});
}
6 changes: 2 additions & 4 deletions packages/realm-web-integration-tests/src/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@
//
////////////////////////////////////////////////////////////////////////////

describe("App services", () => {
require("./remote-mongodb-service.test");
require("./http-service.test");
});
import "./remote-mongodb-service.test";
import "./http-service.test";
7 changes: 4 additions & 3 deletions packages/realm-web-integration-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"compilerOptions": {
"strict": true,
"sourceMap": true,
"module": "commonjs",
"target": "ES2019",
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "Bundler",
"lib": [
"ES2019",
"ES2022",
"DOM"
],
"types": [
Expand Down
2 changes: 1 addition & 1 deletion packages/realm-web-integration-tests/tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"mocha-remote-client"
],
"lib": [
"ES2020",
"ES2022",
"DOM"
]
},
Expand Down
7 changes: 7 additions & 0 deletions packages/realm-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
> [!NOTE]
> This version communicates with Atlas Device Services through a different URL (https://services.cloud.mongodb.com). While we consider this an internal detail of the SDK, you might need to update rules in firewalls or other configuration that you've used to limit connections made by your app.

### Breaking Changes
* The re-exported [bson](https://www.npmjs.com/package/bson) library (via `Realm.BSON`) has been upgraded from 4.7.2 to 6.6.0. ([6561](https://github.com/realm/realm-js/issues/6561))
* Notable changes (refer to BSON's [v5](https://github.com/mongodb/js-bson/releases/tag/v5.0.0) and [v6](https://github.com/mongodb/js-bson/releases/tag/v6.0.0) release notes for all changes):
* Removed `ObjectID` with uppercase `D` (please use `ObjectId`).
* `EJSON` is only exported as the value and not the type (to use it as a type, please use `typeof EJSON`).
* The `Decimal128.bytes` type is now a `Uint8Array` instead of a `Buffer`.

### Deprecations
* None

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.6.0",
"detect-browser": "^5.2.1",
"js-base64": "^3.7.6"
},
Expand Down
26 changes: 22 additions & 4 deletions packages/realm-web/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@
//
////////////////////////////////////////////////////////////////////////////

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({
__SDK_VERSION__: JSON.stringify(pkg.version),
preventAssignment: true,
values: {
__SDK_VERSION__: JSON.stringify(pkg.version),
},
});

export default [
Expand Down Expand Up @@ -97,16 +104,27 @@ export default [
},
],
plugins: [
commonjs(),
typescript({
tsconfig: "src/dom/tsconfig.json",
// Providing an alias for the "bson" package
// See https://github.com/mongodb/js-bson/pull/669#pullrequestreview-1994786536 for more context
alias({
entries: [
{
find: "bson",
replacement: require.resolve("bson"),
},
],
}),
nodeResolve({
mainFields: ["browser", "module", "main"],
exportConditions: ["browser", "module", "main"],
modulesOnly: true,
preferBuiltins: false,
}),
commonjs(),
typescript({
tsconfig: "src/dom/tsconfig.json",
removeComments: true,
}),
replacer,
],
},
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
Loading
Loading