-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client reset w/recovery #4711
Client reset w/recovery #4711
Conversation
2a4c222
to
a5371ce
Compare
4a73a46
to
dff7204
Compare
1b0b9f1
to
2b93d65
Compare
7219b78
to
e753044
Compare
types/index.d.ts
Outdated
enum ClientResetDidRecover { | ||
Yes = 'yes', | ||
No = 'no' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not just a simple boolean
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would allow for latter adding "perhaps - not entirely sure" 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
would be a great way to express that in that theoretical future.
I suggest making this a boolean for now if we're not certain that new values will be added soon.
Alternatively I'd suggest using values that are closer to semantics:
enum ClientResetDidRecover { | |
Yes = 'yes', | |
No = 'no' | |
} | |
enum ClientResetOutcome { | |
Recovered = 'recovered', | |
Discarded = 'discarded' | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another alternative (implemented in other SDKs) is to provide a third callback (similar to the callback for manual mode) which is called when recovery is not possible - or when an error occurs.
integration-tests/realm-apps/with-db-flx/functions/triggerClientReset/config.json
Outdated
Show resolved
Hide resolved
integration-tests/realm-apps/with-db/functions/triggerClientReset/config.json
Outdated
Show resolved
Hide resolved
src/js_sync.hpp
Outdated
arguments[0] = create_object<T, RealmClass<T>>(m_ctx, new SharedRealm(before_realm)); | ||
arguments[1] = create_object<T, RealmClass<T>>(m_ctx, new SharedRealm(after_realm)); | ||
if (!m_ignore_recover) { | ||
arguments[2] = Value<T>::from_string(m_ctx, did_recover ? "yes" : "no"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest this should simply be a boolean
in the user-facing API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An enum is specified in the technical design and will align better with other SDKs
types/index.d.ts
Outdated
type ClientResetAfterCallback = (localRealm: Realm, remoteRealm: Realm) => void; | ||
interface ClientResetConfiguration<ClientResetModeT = ClientResetMode> { | ||
mode: ClientResetModeT; | ||
clientResetBefore?: ClientResetBeforeCallback; | ||
clientResetAfter?: ClientResetAfterCallback; | ||
type ClientResetAfterRecoveryCallback = (localRealm: Realm, remoteRealm: Realm, didRecover: ClientResetDidRecover) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we merge the ClientResetAfterCallback
and ClientResetAfterRecoveryCallback
if we provided false
as default value for didRecover
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didRecover
is something the sync client sets. Moreover, I want to express that didRecover
do not make sense in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should simply call this with false if it couldn't happen. Users providing this callback can simply choose not to read that third argument. I believe the complexity added doesn't outweigh the benefits here.
@@ -1330,7 +1213,7 @@ module.exports = { | |||
|
|||
13) synced, unencrypted Realm -> synced, unencrypted Realm | |||
14) synced, unencrypted Realm -> synced, encrypted Realm | |||
15) synced, encrypted Realm -> synced, unencrypted Realm | |||
15) synced, encrypted Realm -> synced, unencrypted Relam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
15) synced, encrypted Realm -> synced, unencrypted Relam | |
15) synced, encrypted Realm -> synced, unencrypted Realm |
@@ -361,7 +361,7 @@ module.exports = { | |||
const credentials = Realm.Credentials.anonymous(); | |||
return app.logIn(credentials).then((user) => { | |||
return new Promise((resolve, _reject) => { | |||
const config = getSyncConfiguration(user, partition); | |||
let config = getSyncConfiguration(user, partition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seem like an unneeded change to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this API makes more sense 👍
Manual: "manual", | ||
DiscardLocal: "discardLocal", | ||
DiscardUnsyncedChanges: "discardUnsyncedChanges", | ||
RecoverUnsyncedChanges: "recoverUnsyncedChanges", | ||
RecoverOrDiscardUnsyncedChanges: "recoverOrDiscardUnsyncedChanges", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing: DiscardLocal = 'discardLocal'
e845294
to
ee75117
Compare
Co-authored-by: Kræn Hansen <[email protected]>
6c6603e
to
e28658a
Compare
* Add new client reset modes * Expand manual mode Co-authored-by: Kræn Hansen <[email protected]>
* Add new client reset modes * Expand manual mode Co-authored-by: Kræn Hansen <[email protected]>
@@ -438,13 +612,6 @@ void SessionClass<T>::get_config(ContextType ctx, ObjectType object, ReturnValue | |||
Value::from_string(ctx, String::from_bson(partition_value_bson))); | |||
} | |||
|
|||
auto conf = session->config(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kneth What was the reasoning of removing error
from the returned sync configuration?
What, How & Why?
This closes #4135
☑️ ToDos
Compatibility
label is updated or copied from previous entrypackage.json
s (if updating internal packages)Breaking
label has been applied or is not necessaryIf this PR adds or changes public API's:
[ ] Chrome debug API is updated if API is available on React Native