Skip to content

Commit

Permalink
Merge de6a9ab into 6269081
Browse files Browse the repository at this point in the history
  • Loading branch information
elle-j committed Apr 26, 2024
2 parents 6269081 + de6a9ab commit 71123cf
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 4 deletions.
2 changes: 2 additions & 0 deletions integration-tests/tests/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import "./tests/credentials/email-password";
import "./tests/credentials/function";
import "./tests/credentials/jwt";

import "./tests/experimental/base-url";

import "./tests/sync/app";
import "./tests/sync/asymmetric";
import "./tests/sync/client-reset";
Expand Down
35 changes: 35 additions & 0 deletions integration-tests/tests/src/tests/experimental/base-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
////////////////////////////////////////////////////////////////////////////
//
// 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 { App } from "realm";
import "realm/experimental/base-url";

describe("Experimental", () => {
it("updates base URL", function (this: Mocha.Context) {
const app = new App("12345");
expect(app.baseUrl).equals("https://services.cloud.mongodb.com");

// @ts-expect-error Assigning to read-only property.
expect(() => (app.baseUrl = "new URL")).to.throw("Cannot assign the base URL, please use `updateBaseUrl()`");
expect(app.baseUrl).equals("https://services.cloud.mongodb.com");

// Update to a URL that will not work.
expect(app.updateBaseUrl("https://example")).to.be.rejectedWith("Error: request to https://example/");
});
});
4 changes: 2 additions & 2 deletions integration-tests/tests/tsconfig.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"composite": true,
"target": "es2022",
"module": "es2022",
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"useDefineForClassFields": false,
"strict": true,
"strictFunctionTypes": false,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
{ "path": "./tsconfig.common.json" },
{ "path": "./tsconfig.node.json" }
]
}
}
2 changes: 1 addition & 1 deletion integration-tests/tests/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "@tsconfig/node-lts",
"compilerOptions": {
"composite": true,
"module": "es2022",
"module": "node16",
"moduleResolution": "Bundler",
"outDir": "dist",
"strictFunctionTypes": false,
Expand Down
2 changes: 2 additions & 0 deletions packages/realm/bindgen/js_opt_in_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ classes:
- unsubscribe
- call_function
- make_streaming_request
- update_base_url
- get_base_url

WatchStream:
methods:
Expand Down
4 changes: 4 additions & 0 deletions packages/realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"node": "./dist/platform/node/index.js",
"react-native": "./index.react-native.js"
},
"./experimental/base-url": {
"types": "./dist/public-types/experimental/base-url.d.ts",
"default": "./dist/experimental/base-url.js"
},
"./scripts/submit-analytics": "./scripts/submit-analytics.mjs",
"./react-native.config.js": "./react-native.config.js",
"./package.json": "./package.json"
Expand Down
48 changes: 48 additions & 0 deletions packages/realm/src/experimental/base-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////////////////////
//
// 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" {
interface App {
/**
* Get the current base URL used for sending requests to Atlas App Services.
* @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.
* @experimental This feature is experimental and may be changed or removed.
*/
updateBaseUrl(url: string): 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, url: string) {
return this.internal.updateBaseUrl(url);
};

0 comments on commit 71123cf

Please sign in to comment.