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-2732: Support updating the App's base URL via experimental export #6518

Merged
merged 22 commits into from
May 1, 2024

Conversation

elle-j
Copy link
Contributor

@elle-j elle-j commented Feb 29, 2024

What, How & Why?

Experimental exports/imports

  • An experimental directory has been added (packages/realm/src/experimental), intended for exporting various experimental features.

Base URL

  • Importing "realm/experimental/base-url" will extend the App with the instance members App.baseUrl and App.updateBaseUrl(), allowing the user to retrieve and update the base URL.

TSConfig / Choosing module resolution

  • Importing the experimental package will only work with certain resolution algorithms. Example tsconfig.json:
{
  "compilerOptions": {
    "target": "es2022",
    "module": "node16",
    "moduleResolution": "node16",
    // ...
  }
}

Example Usage

import { App } from "realm";
import "realm/experimental/base-url";

async function exampleFunction() {
  const app = new App("my-atlas-app-id");

  // Get the currently used base URL.
  const currentBaseUrl = app.baseUrl;

  // Update the base URL.
  await app.updateBaseUrl("https://my-new-url.com");

  // Reset it to the default one.
  await app.updateBaseUrl(null);
}

This closes #6486

☑️ ToDos

  • 📝 Changelog entry
  • 🚦 Tests (but need to add follow-ups to skipped unimplemented tests)

@elle-j elle-j changed the title Support exporting experimental features from realm/experimental RJS-2732: Support updating the App's base URL via experimental export Apr 26, 2024
Copy link
Member

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Might be worth adding a smoke test that updating the base url to a valid url also works. We could try and use realm.mongodb.com since that domain should still work.

@elle-j
Copy link
Contributor Author

elle-j commented Apr 26, 2024

Just reviving the old draft implementation then I'll be modifying the test and adding some more 🙂

Comment on lines 32 to 35
it.skip("updates the URL", async function (this: AppContext) {
// TODO
});
Copy link
Contributor Author

@elle-j elle-j Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add this using a fetch mock.

@@ -3,7 3,7 @@
"composite": true,
"target": "es2022",
"module": "es2022",
"moduleResolution": "node",
"moduleResolution": "Bundler",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check this works with npm test --workspace @realm/integration-tests (where we use raw Mocha and tsx to transpile TypeScript)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works ✅


// This file is needed as a workaround for Metro unexpectedly failing
// to use the entry point defined in the package.json `exports` field,
// despite enabling `unstable_enablePackageExports`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well - even if this wasn't a problem, we would probably need this file anyway, to workaround the fact that unstable_enablePackageExports is disabled by default 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ... I know for a fact that the Metro team would be very grateful if someone would set up some tests of the metro resolver (most likely copying in tests from other packages / tools). This would make a good test case if the pattern isn't already covered by one of those other tests.

Copy link
Contributor Author

@elle-j elle-j May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the comment to incorporate being disabled by default. Feel free to suggest any additional changes you think would be relevant for this file 👍

I'd be glad to look over some of the Metro tests and see what could be added. At first glance, it does seem like their tests are covering subpath exports.

@@ -1107,7 1107,7 @@ PODS:
- React-Core
- React-jsi
- ReactTestApp-Resources (1.0.0-dev)
- RealmJS (12.7.0-rc.0):
- RealmJS (12.7.1):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this was not already on main 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just didn't get committed 🤷‍♀️

Copy link
Contributor

@kneth kneth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@elle-j elle-j marked this pull request as ready for review May 1, 2024 13:53
@elle-j elle-j requested a review from kneth May 1, 2024 13:53
@elle-j
Copy link
Contributor Author

elle-j commented May 1, 2024

@kneth, for the final review there are only minor changes to look at:

  • CHANGELOG.md
  • packages/realm/src/experimental/base-url.ts: Per another discussion, the API updateBaseUrl() now accepts null as a way to reset the base URL to the default one (in addition to empty string).

Still missing:

  • Haven't got the mock fetch to work yet, so I'll add a ticket to implement the skiped tests.

@elle-j elle-j merged commit 7f6535f into main May 1, 2024
33 checks passed
@elle-j elle-j deleted the lj/experimental branch May 1, 2024 14:34
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

baseUrl Change (Realm JS)
4 participants