realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

Upgrade to BSON v6

Open kraenhansen opened this issue 1 year ago • 3 comments

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.

kraenhansen avatar Mar 18 '24 21:03 kraenhansen

➤ PM Bot commented:

Jira ticket: RJS-2765

sync-by-unito[bot] avatar Mar 18 '24 21:03 sync-by-unito[bot]

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).

elle-j avatar Apr 12 '24 09:04 elle-j

@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.

kraenhansen avatar Apr 29 '24 08:04 kraenhansen