Skip to content

Commit

Permalink
Made determinePath use syncManager from user
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Mar 1, 2023
1 parent 239e640 commit 7e2beeb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/realm/src/Realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,8 @@ export class Realm {
if (config.path || !config.sync || config.openSyncedRealmLocally) {
return Realm.normalizePath(config.path);
} else {
// TODO: Determine if it's okay to get the syncManager through the app instead of the user:
// return user->m_user->sync_manager()->path_for_realm(*(config.sync_config));
const bindingSyncConfig = toBindingSyncConfig(config.sync);
return config.sync.user.app.internal.syncManager.pathForRealm(bindingSyncConfig);
return config.sync.user.internal.syncManager.pathForRealm(bindingSyncConfig);
}
}

Expand Down
15 changes: 13 additions & 2 deletions packages/realm/src/app-services/SyncSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ type ListenerToken = {
token: binding.Int64;
};

/**
* With the current properties available through Core, it it's possible to construct an app from a user nor sync session internal.
* TODO: Refactor to pass an app instance through to all places that constructs a SyncSession.
*/
const mockApp = new Proxy({} as App, {
get() {
throw new Error("Using user.app of a user returned through syncSession.config is not supported");
},
});

/**
* Progress listeners are shared across instances of the SyncSession, making it possible to deregister a listener on another session
* TODO: Consider adding a check to verify that the callback is removed from the correct SyncSession (although that would break the API)
Expand Down Expand Up @@ -272,9 +282,10 @@ export class SyncSession {
this._internal = null;
}

// TODO: Return the `error_handler` and `custom_http_headers`
// TODO: Return the `error_handler`
// TODO: Figure out a way to avoid passing a mocked app instance when constructing the User.
get config(): SyncConfiguration {
const user = new User(this.internal.user, {} as unknown as App);
const user = new User(this.internal.user, mockApp);
const { partitionValue, flxSyncRequested, customHttpHeaders } = this.internal.config;
if (flxSyncRequested) {
return { user, flexible: true, customHttpHeaders };
Expand Down

0 comments on commit 7e2beeb

Please sign in to comment.