-
Notifications
You must be signed in to change notification settings - Fork 576
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
Merge Realm JS and Realm Web types #2950
Conversation
e8b2d7a
to
a559969
Compare
3c1205d
to
95544ea
Compare
} | ||
|
||
public async refreshCustomData() { | ||
await this.refreshAccessToken(); |
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.
So in reality, an exception is thrown, right?
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.
Yeah, for now :) Until #2967 gets fixed.
what does this means
I find it problematic to have the return type differ. Sometimes returning |
Ideally this would just be It's because Realm Web sends a request (like the legacy SDKs) but that doesn't seem to be implemented in the way Object Store logs out a user - or it's implemented in a way that allows it to fail silently. I propose we change it to make Realm JS return a resolved |
exactly what I was thinking. if its a synchronous call in some cases this should return a resolved Promise. |
packages/realm-web/src/App.ts
Outdated
// Add the user at the top of the stack | ||
this.users.splice(0, 0, handle); | ||
this.users.splice(0, 0, user); |
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.
unshift
would just take the user.
@@ -153,13 +114,7 @@ export class User implements Realm.User { | |||
private _state: Realm.UserState; | |||
private transport: AuthenticatedTransport; |
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.
A bit inconsistency in prefixing props marked as private
with _
.
Have we considered to switching away from TS public
/private
keyword (which doesn't translate ti JS), and adopt JS private class fields.
I'm pretty sure latest versions of TS will emulates the runtime behaviour of private fields the best it can.
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.
The private fields with an _
prefix is only because the class also has a public getter overloading the name. It could be called internalState
or something else. But I actually think this specific fields goes away in one of the later PRs.
With regards to JS private fields. It's valuable to keep an eye on, but I don't think the adoption in browsers are good enough for us to rely on. And I don't know the state of polyfils for this?
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 TS handles that, but I'm not sure (as in I haven't tested it) microsoft/TypeScript#30829
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.
Oh ...
5c68a02
to
e88cbd5
Compare
40bd1e7
to
b7476c1
Compare
Co-authored-by: Kenneth Geisshirt <kenneth.geisshirt@mongodb.com>
b7476c1
to
de28eb4
Compare
packages/realm-web/src/App.ts
Outdated
} | ||
public switchUser(nextUser: User<FunctionsFactoryType, CustomDataType>) { | ||
const index = this.users.findIndex(u => u === nextUser); | ||
if (index >= 0) { |
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.
index !== -1
might be more precise
// Remove the user from the list of users | ||
const index = this.users.findIndex(({ user: u }) => u === user); | ||
const index = this.users.findIndex(u => u === user); |
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.
Will we always find a user?
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.
If not, findIndex
will return -1
, which would result in a bug, since the first argument of splice states:
An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array
types/app.d.ts
Outdated
logOut(): Promise<void>; | ||
|
||
/** | ||
* Link the user with a new identity represented by another set of credentials. |
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.
* Link the user with a new identity represented by another set of credentials. | |
* Link the user with an identity represented by another set of credentials. |
types/app.d.ts
Outdated
linkCredentials(credentials: Credentials): Promise<void>; | ||
|
||
/** | ||
* Call a remote MongoDB Realm function by it's name. |
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.
* Call a remote MongoDB Realm function by it's name. | |
* Call a remote MongoDB Realm function by its name. |
* Renamed UserAPIKeyProvider to ApiKeyAuth * Renaming instance methods * Moved from user.auth.apiKeys to user.apiKeys * Renamed js_user_apikey_provider.hpp to js_api_key_auth.hpp * Updated the jsdocs * Adding apiKeys to the browser proxy * Adding a note in the changelog
349b594
to
a65b534
Compare
* Renamed to js_email_password_auth.hpp, email-password-auth-methods.js and api-key-auth-methods.js * Adding a note in the changelog * Updated docs * Renamed to EmailPasswordAuth
* registerEmail -> registerUser * Realm.User.identity -> Realm.User.id. Realm.User.token -> Realm.User.accessToken. Add Realm.User.refreshToken. * Turn Realm.App.{currentUser, allUsers} to an instance property * Add Realm.Auth.EmailPassword.callResetPasswordFunction * Wrongly merged
What, How & Why?
The purpose of this PR is to merge duplicated type definitions (such as
App
,User
,UserProfile
) across ´types/index.d.ts` and the other files in that directory.I propose the following changes to the Realm JS types:
User
related changes:identity
onUser
toid
(to align with other SDKs and avoid confusion from authentication provideridentities
returned when fetching the user profile).token
toaccessToken
(to make it more obvious what token this is) and add therefreshToken
as a property (this is up for debate - but it makes it easier to test the User implementation).customData
to use a generic type defined byUser
and theApp
(like we do forFunctionsFactoryType
) to allow users of the API to define types for this custom data, once (when creating the app instance).logOut
toPromise<void> | void
, since it sends a request to invalidate the refresh token.App
related changes:allUsers
from a method to a getter-property returning a list instead of aUserMap
.currentUser
from a method to a getter-property.removeUser
return aPromise<void>
instead ofPromise<User>
, since that user would have limited use anyway.Auth
related changes:API*
toApi
.Auth
to the class names (Realm.Auth.ApiKeyAuth
andRealm.Auth.EmailPasswordAuth
).callResetPasswordFunction
which was part of the existing Stitch SDK.I propose the following changest to the Realm Web Types:
App
related changes:string
as a valid argument on methods called with a user parameter (it was ment to enable users to pass in a user ID instead of a user object).UserProfile
related changes:pictureURL
topictureUrl
.Auth
related changes:ApiKeyProvider
toApiKeyAuth
.EmailPasswordProvider
toEmailPasswordAuth
.get
andlist
tofetch
andfetchAll
respectively, on theApiKeyProvider
.resendConfirmation
toresendConfirmationEmail
on theEmailPasswordProvider
.These changes lead to some simplifications of the way user state is managed by the app, which also found its way into this PR.