Page MenuHomePhabricator

[lib, web, natvie] Add sessionID field to keyserverStore
ClosedPublic

Authored by inka on Jul 27 2023, 7:52 AM.
Tags
None
Referenced Files
F2158302: D8644.diff
Mon, Jul 1, 3:33 AM
Unknown Object (File)
Fri, Jun 21, 10:25 PM
Unknown Object (File)
Fri, Jun 21, 10:25 PM
Unknown Object (File)
Tue, Jun 18, 10:04 PM
Unknown Object (File)
Tue, Jun 18, 10:03 PM
Unknown Object (File)
Thu, Jun 13, 9:22 PM
Unknown Object (File)
May 29 2024, 4:08 AM
Unknown Object (File)
May 20 2024, 6:31 AM
Subscribers

Details

Summary

issue: https://linear.app/comm/issue/ENG-4457/refactor-sessionid-field
Adding sessionID to keyserverStore. Not reducing it yet.

Test Plan

Tested that sessionID field is present in the keyseverStore. Checked that it is set to the same value as sessionID initilly.
Ran yarn flow-all.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

inka requested review of this revision.Jul 27 2023, 8:10 AM
lib/utils/sanitization.js
298 ↗(On Diff #29138)

This issue is not present in the newest flow, so I'm assuming it can be ignored. I tried fixing it, but didn't manage to

Cannot spread object literal because  null or undefined [1] is incompatible with  undefined [2] in property `sessionID`.Flow(incompatible-type)
307 ↗(On Diff #29138)

This issue is present in the newest flow.

Cannot assign object literal to `state` because  null or undefined [1] is incompatible with  undefined [2] in property `sessionID` of the indexer property of property `keyserverStore.keyserverInfos`.Flow(incompatible-type)

flow doesn't know which KeyserverInfo type keyserverInfos has. I couldn't fix this, but this code is very straightforward

Not a fan of using *, from what I understand that's basically any. I think we could use generics instead (we could also replace the * that existed before if we are changing the code anyway). There's also the option of using empty in places where we aren't using the generic fields, which would be "safer" because we wouldn't be able to use them, but this doesn't feel very clear.

lib/types/keyserver-types.js
12 ↗(On Diff #29138)

What is the reason for using ... and $Exact<>?

38 ↗(On Diff #29138)

Nit: can we name it keyserverInfoType or something more descriptive?

lib/utils/sanitization.js
298 ↗(On Diff #29138)

Can you make a task for it and add it to ENG-4283 so we don't forget about it?

Agree with @michal... wondering, what if we use a default type param here? Then we could just use BaseAppState<>.

To declare a default type param, add an = DefaultType after the : BaseType. Often you use the same type for both, eg. BaseAppState<NavInfo: BaseNavInfo = BaseNavInfo>, which causes BaseAppState<> to expand into BaseAppState<BaseNavInfo>

lib/types/keyserver-types.js
12 ↗(On Diff #29138)

Using ... makes the type behave more like an interface - it's possible to have a function that takes infos: BaseKeyserverInfos and pass any of WebKeyserverInfo or NativeKeyserverInfo to it (but only be able to access properties from BaseKeyserverInfo).
I used $Exact<> in WebKeyserverInfo and NativeKeyserverInfo, because we want those types to be exact, for better type checking.

I could have instead done:

export type BaseKeyserverInfo = {
  +cookie?: ?string,
};

export type WebKeyserverInfo = {
  ...BaseKeyserverInfo,
  +sessionID: ?string,
};

export type NativeKeyserverInfo = {
  ...BaseKeyserverInfo,
  +sessionID?: void,
};

it's just a bit less flexible. But since we have WebKeyserverInfo, NativeKeyserverInfo and KeyserverInfo in lib, I guess I can always use KeyserverInfo wherever I'd want to use BaseKeyserverInfo as an "interface". So if you think I should change it, then it shouldn't be a problem.
I'm not sure if there are any straighforward advantages of using the second approach?

wondering, what if we use a default type param here?

No, this causes errors

Cannot call useSelector with threadInfoSelector bound to selector because undefined [1] is incompatible with null or
undefined [2] in property sessionID of type argument KeyserverInfoType [3] of property keyserverStore of the first
parameter. [incompatible-call]

I think we could use generics instead

I can't use generis for consts, mixed also doesn't seem to work

Managed to remove all // Flow-issues, but there is one type error hidden under that clone any typed

ashoat requested changes to this revision.Jul 31 2023, 11:50 AM

I'd really like to see a solution that doesn't use *, any, or $FlowFixMe. I'm not sure, but I suspect that this is possible here. I've created a start for you with D8685 and D8686. Can you please rebase this diff on top of that stack, and try to find a way forward without using *?

This revision now requires changes to proceed.Jul 31 2023, 11:50 AM

I reabsed over D8686 and removed the * from my changes. Me @michal and @tomek spent a lot of time trying to make the solution with two KeyserverInfos work, but we couldn't get it to work without flow errors. We figured it's not worth spending so much time on.
I created https://linear.app/comm/issue/ENG-4568/improve-sessionid-type to fix this at some point, but for now I will type sessionID as sessionID?: ?string, and use the same KeyserverInfo for web and native. This significantly simplifies the code. As of now, there should be no other fields that have different type on web than on native, so this issue shouldn't reoccur for now

Okay, fair enough – I agree it's not worth that much effort. Especially if all three of you had trouble

This revision is now accepted and ready to land.Aug 2 2023, 5:18 AM