Skip to content

Commit

Permalink
Use recommended presets for OpenRealmBehaviorConfiguration (#5949)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Meyer <[email protected]>
  • Loading branch information
papafe and takameyer authored Jul 11, 2023
1 parent e1a87a9 commit 1274da4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
11 changes: 7 additions & 4 deletions integration-tests/tests/src/tests/sync/open-behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -33,7 +33,7 @@ const DogForSyncSchema = {
},
};

async function getRegisteredEmailPassCredentials(app: Realm.App) {
async function getRegisteredEmailPassCredentials(app: Realm.App<any, any>) {
if (!app) {
throw new Error("No app supplied to 'getRegisteredEmailPassCredentials'");
}
Expand All @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion packages/realm/src/ProgressRealmPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/realm/src/app-services/Sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenRealmBehaviorConfiguration> = {
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<OpenRealmBehaviorConfiguration> = {
type: OpenRealmBehaviorType.DownloadBeforeOpen,
Expand Down
12 changes: 12 additions & 0 deletions packages/realm/src/app-services/SyncConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down

0 comments on commit 1274da4

Please sign in to comment.