Skip to content

Commit

Permalink
Merge 2abad39 into 6e60915
Browse files Browse the repository at this point in the history
  • Loading branch information
elle-j committed Feb 29, 2024
2 parents 6e60915 + 2abad39 commit 4e1c01c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 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
33 changes: 33 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,33 @@
////////////////////////////////////////////////////////////////////////////
//
// 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("switches base URL", function (this: Mocha.Context) {
const app = new App("12345");
expect(app.baseUrl).equals("https://example");
// @ts-expect-error Assigning to read-only property.
expect(() => (app.baseUrl = "new URL")).to.throw("Cannot assign the base URL, please use `switchBaseUrl()`");
expect(app.baseUrl).equals("https://example");
// With the dummy implementation it doesn't actually switch anything.
app.switchBaseUrl("something else");
});
});
4 changes: 2 additions & 2 deletions integration-tests/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"useDefineForClassFields": false,
"strict": true,
"strictFunctionTypes": false,
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 base URL.
*/
get baseUrl(): string;
/**
* Switch the base URL.
*/
switchBaseUrl(url: string): void;
}
}

Object.defineProperty(App.prototype, "baseUrl", {
get() {
// TODO: Implementation
console.log(`(App ID: ${this.id}) Returning base URL..`);
return "https://example";
},
set() {
throw new Error("Cannot assign the base URL, please use `switchBaseUrl()`.");
},
});

App.prototype.switchBaseUrl = function (this: App) {
// TODO: Implementation
console.log(`(App ID: ${this.id}) Switching base URL..`);
};

0 comments on commit 4e1c01c

Please sign in to comment.