-
Notifications
You must be signed in to change notification settings - Fork 584
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
Changes from all commits
382d5e3
8d8f468
fb93561
1364f06
ffd94e4
4cb4b21
3c443ae
b6977e3
0275ee3
e49a689
b1350cf
83599ff
d6dd6db
f41e9af
0e3cd2d
7406cf4
1ccfd57
47801ab
dd6cbd4
ddb63b0
7f449eb
1bc1027
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2024 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
import { expect } from "chai"; | ||
import "realm/experimental/base-url"; | ||
|
||
import { baseUrl as originalBaseUrl, importAppBefore } from "../../hooks"; | ||
import { buildAppConfig } from "../../utils/build-app-config"; | ||
|
||
describe.skipIf(environment.missingServer, "Base URL", () => { | ||
importAppBefore(buildAppConfig("with-anon").anonAuth()); | ||
|
||
it("returns the base URL used", function (this: AppContext) { | ||
expect(this.app.baseUrl).equals(originalBaseUrl); | ||
}); | ||
|
||
// TODO: Should implement when I've got a working fetch mock. | ||
it.skip("updates the URL", async function (this: AppContext) { | ||
// TODO | ||
}); | ||
Comment on lines
+33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will add this using a fetch mock. |
||
|
||
it.skip("resets to default URL", async function (this: AppContext) { | ||
// TODO | ||
}); | ||
|
||
it("throws when assigning via setter", function (this: AppContext) { | ||
// @ts-expect-error Assigning to read-only property. | ||
expect(() => (this.app.baseUrl = "new URL")).to.throw("Cannot assign the base URL, please use 'updateBaseUrl()'"); | ||
|
||
expect(this.app.baseUrl).equals(originalBaseUrl); | ||
}); | ||
|
||
it("rejects when updating to invalid URL", async function (this: AppContext) { | ||
await expect(this.app.updateBaseUrl("https://invalid")).to.be.rejectedWith( | ||
"request to https://invalid/api/client/", | ||
); | ||
|
||
expect(this.app.baseUrl).equals(originalBaseUrl); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"composite": true, | ||
"target": "es2022", | ||
"module": "es2022", | ||
"moduleResolution": "node", | ||
"moduleResolution": "Bundler", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you check this works with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works ✅ |
||
"useDefineForClassFields": false, | ||
"strict": true, | ||
"strictFunctionTypes": false, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
{ "path": "./tsconfig.common.json" }, | ||
{ "path": "./tsconfig.node.json" } | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2024 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
// Our use of `exports` in `packages/realm/package.json` is not enabled by | ||
// default when using Metro and RN. In these cases, modules imported from | ||
// "realm/experimental" will search for the file in the same path, rather | ||
// than what is pointed to under `exports`. Thus, we use this .js file to | ||
// in turn import the necessary module. | ||
|
||
// (Enabling `unstable_enablePackageExports` in the metro config unexpectedly | ||
// does not work.) | ||
|
||
/* eslint-env commonjs */ | ||
module.exports = require("../dist/experimental/base-url"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2024 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
import { App } from "../app-services/App"; | ||
|
||
declare module "../app-services/App" { | ||
elle-j marked this conversation as resolved.
Show resolved
Hide resolved
|
||
interface App { | ||
/** | ||
* Get the current base URL used for sending requests to Atlas App Services. | ||
* | ||
* If an {@link App.updateBaseUrl | updateBaseUrl} operation is currently in | ||
* progress, this value will not be updated with the new value until that | ||
* operation has completed. | ||
* @experimental This feature is experimental and may be changed or removed. | ||
*/ | ||
get baseUrl(): string; | ||
|
||
/** | ||
* Update the base URL used for sending requests to Atlas App Services. If this is | ||
* set to an empty string or `null`, it will reset the base URL to the default one. | ||
* | ||
* If this operation fails, the app will continue to use the original base URL. | ||
* If another {@link App} operation is started while this function is in progress, | ||
* that request will use the original base URL location information. | ||
* @experimental This feature is experimental and may be changed or removed. | ||
*/ | ||
updateBaseUrl(newUrl: string | null): Promise<void>; | ||
} | ||
} | ||
|
||
Object.defineProperty(App.prototype, "baseUrl", { | ||
get(this: App) { | ||
return this.internal.getBaseUrl(); | ||
}, | ||
set() { | ||
throw new Error("Cannot assign the base URL, please use 'updateBaseUrl()'."); | ||
}, | ||
}); | ||
|
||
App.prototype.updateBaseUrl = function (this: App, newUrl: string | null) { | ||
return this.internal.updateBaseUrl(newUrl ?? undefined); | ||
}; |
There was a problem hiding this comment.
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
🤔There was a problem hiding this comment.
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 🤷♀️