realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.62k stars 558 forks source link

Upgrade to BSON v6 #6561

Open kraenhansen opened 2 months ago

kraenhansen commented 2 months ago

The public types emitted for bson.d.ts are wrong:

export declare namespace BSON {
    const ObjectId: typeof bson.ObjectID; // 👈 notice the capital D in ID
    type ObjectId = bson.ObjectId;
    const ObjectID: typeof bson.ObjectID;
    type ObjectID = bson.ObjectID;
    // ...
}

This is really weird since we're importing the right type from the namespace:

https://github.com/realm/realm-js/blob/1e1e48a0f906d471b4a046168ed8cd628ef2d70f/packages/realm/src/bson.ts#L27-L30

We should be able to upgrade to bson@6 by now and this will fix the issue since that has removed ObjectID (capital D) entirely.

sync-by-unito[bot] commented 2 months ago

➤ PM Bot commented:

Jira ticket: RJS-2765

elle-j commented 1 month ago

Adding the same notes as in the corresponding PR description regarding being blocked:

The BSON package is currently using top-level await which currently prevents us from bundling if don't enable that feature. @kraenhansen has contributed a PR to BSON to alleviate this for us (see Jira ticket).

kraenhansen commented 3 weeks ago

@elle-j and I looked further into this last week and realized:

  1. bson@6 is relying soly on exports conditions to expose its React Native bundle: https://github.com/mongodb/js-bson/blob/c58d1e213714c99bbb09d0f91a3c9199e43710dd/package.json#L90. This problematic, because Metro is currently considering its ability to resolve using exports conditions "experimental" and its disabled by default.
  2. The way the base64 dependency is required by the React Native bundle, confuses Metro. We need to investigate this further, but our current suspicion is the use of a "sub-package" / "bundled dependency", in the sense that the vendored "base64" is resolved via a "package.json" which is included in a sub-directory of the "bson" package.