From 1274da4d20ed35f950531c7268303c91742c1da2 Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 11 Jul 2023 11:19:12 +0200 Subject: [PATCH] Use recommended presets for `OpenRealmBehaviorConfiguration` (#5949) Co-authored-by: Andrew Meyer --- .../tests/src/tests/sync/open-behavior.ts | 11 +++++++---- packages/realm/src/ProgressRealmPromise.ts | 6 +++++- packages/realm/src/app-services/Sync.ts | 3 +++ packages/realm/src/app-services/SyncConfiguration.ts | 12 ++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/integration-tests/tests/src/tests/sync/open-behavior.ts b/integration-tests/tests/src/tests/sync/open-behavior.ts index 4bb9421dce..ea47bf7563 100644 --- a/integration-tests/tests/src/tests/sync/open-behavior.ts +++ b/integration-tests/tests/src/tests/sync/open-behavior.ts @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////////////// import { expect } from "chai"; -import Realm, { BSON } from "realm"; +import Realm, { BSON, OpenRealmBehaviorType, OpenRealmTimeOutBehavior } from "realm"; import { generatePartition, randomVerifiableEmail } from "../../utils/generators"; import { importAppBefore } from "../../hooks"; import { sleep } from "../../utils/sleep"; @@ -33,7 +33,7 @@ const DogForSyncSchema = { }, }; -async function getRegisteredEmailPassCredentials(app: Realm.App) { +async function getRegisteredEmailPassCredentials(app: Realm.App) { if (!app) { throw new Error("No app supplied to 'getRegisteredEmailPassCredentials'"); } @@ -52,8 +52,11 @@ describe("OpenBehaviour", function () { afterEach(() => Realm.clearTestState()); it("static references are defined", () => { - expect(Realm.App.Sync.openLocalRealmBehavior).to.not.be.undefined; - expect(Realm.App.Sync.downloadBeforeOpenBehavior).to.not.be.undefined; + expect(Realm.App.Sync.openLocalRealmBehavior.type).to.equal(OpenRealmBehaviorType.OpenImmediately); + + expect(Realm.App.Sync.downloadBeforeOpenBehavior.type).to.equal(OpenRealmBehaviorType.DownloadBeforeOpen); + expect(Realm.App.Sync.downloadBeforeOpenBehavior.timeOut).to.equal(30000); + expect(Realm.App.Sync.downloadBeforeOpenBehavior.timeOutBehavior).to.equal(OpenRealmTimeOutBehavior.ThrowException); }); it("open synced realm with localRealmBehaviour", async function (this: AppContext) { diff --git a/packages/realm/src/ProgressRealmPromise.ts b/packages/realm/src/ProgressRealmPromise.ts index fbd8078cbd..9a12e6e343 100644 --- a/packages/realm/src/ProgressRealmPromise.ts +++ b/packages/realm/src/ProgressRealmPromise.ts @@ -52,7 +52,11 @@ function determineBehavior(config: Configuration, realmExists: boolean): OpenBeh } return { openBehavior: type, timeOut, timeOutBehavior }; } else { - return { openBehavior: OpenRealmBehaviorType.DownloadBeforeOpen }; // Default is downloadBeforeOpen + return { + openBehavior: OpenRealmBehaviorType.DownloadBeforeOpen, + timeOut: 30 * 1000, + timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException, + }; } } } diff --git a/packages/realm/src/app-services/Sync.ts b/packages/realm/src/app-services/Sync.ts index cf65619839..c1dcfcd626 100644 --- a/packages/realm/src/app-services/Sync.ts +++ b/packages/realm/src/app-services/Sync.ts @@ -174,13 +174,16 @@ export class Sync { /** * The default behavior settings if you want to open a synchronized Realm immediately and start working on it. * If this is the first time you open the Realm, it will be empty while the server data is being downloaded in the background. + * @deprecated since v12 */ + static openLocalRealmBehavior: Readonly = { type: OpenRealmBehaviorType.OpenImmediately, }; /** * The default behavior settings if you want to wait for downloading a synchronized Realm to complete before opening it. + * @deprecated since v12 */ static downloadBeforeOpenBehavior: Readonly = { type: OpenRealmBehaviorType.DownloadBeforeOpen, diff --git a/packages/realm/src/app-services/SyncConfiguration.ts b/packages/realm/src/app-services/SyncConfiguration.ts index ae75d210ba..9dda0de918 100644 --- a/packages/realm/src/app-services/SyncConfiguration.ts +++ b/packages/realm/src/app-services/SyncConfiguration.ts @@ -220,11 +220,23 @@ export type BaseSyncConfiguration = { user: AnyUser; /** * Whether to create a new file and sync in background or wait for the file to be synced. + * @default + * { + * type: OpenRealmBehaviorType.DownloadBeforeOpen, + * timeOut: 30 * 1000, + * timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException, + * } */ newRealmFileBehavior?: OpenRealmBehaviorConfiguration; /** * Whether to open existing file and sync in background or wait for the sync of the file to complete and then open. * If not set, the Realm will be downloaded before opened. + * @default + * { + * type: OpenRealmBehaviorType.DownloadBeforeOpen, + * timeOut: 30 * 1000, + * timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException, + * } */ existingRealmFileBehavior?: OpenRealmBehaviorConfiguration; /**