-
Notifications
You must be signed in to change notification settings - Fork 3
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
Arv/presence state #21
Conversation
I got rid of the "singleton" case. Started enforcing correct clientID in write but needs more tests. Started writing tests for optional/empty id/clientID. Needs more work!!! |
bd904f9
to
716dbcc
Compare
This adds a function called `generatePresence` that generates a collection of presence keys at `-/p/${clientID}/name/${id}`. The type of these entities are called `PresenceEntity` and are defined as: ```ts type PresenceEntity = { clientID: string; id: string; }; ``` When looking up a presence state value, if the `id` is omitted, the `id` is set to `''` and if the `clientID` is omitted, the `clientID` is set to the `clientID` of the current client. When writing and mutating the value the `id` and the `clientID` are added to the value if they are missing. You can only mutate the presence state value for the current client. If you try to mutate a value that has different `clientID` than the current client a runtime error is thrown.
716dbcc
to
b2391e0
Compare
@aboodman This is |
For `get`, `mustGet`, `has` and `delete`. When undefined we treat it as `{clientID: tx.clientID, id: ''}`.
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.
LGTM
```ts | ||
type Cursor { | ||
clientID: string; | ||
id: '', |
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 we could make id
optional and default it to empty string, 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 played around with that.
It has some weirdness to only do this at the type level.
- If you use strict parse in zod (not default) or in valita (default) the extra field (
id
) in the results causes errors. - The
id
is always present in the result (get) and in the keys for the entries.
If we do this we should make the resulting types declare that it is always present at least.
export type OptionalIDs<T extends PresenceEntity> = Partial<T> & | ||
Omit<T, keyof PresenceEntity>; | ||
|
||
export type LookupID = Partial<PresenceEntity>; |
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 might call this PresenceID
just to make it a little more clear from name only, when using the type from outside the package.
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.
Good idea
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.
Done in #23
No description provided.