-
Notifications
You must be signed in to change notification settings - Fork 11.8k
chore: Internally operate Minimongo collections over Zustand stores (as transition for stores-only) #35470
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
Merged
Merged
chore: Internally operate Minimongo collections over Zustand stores (as transition for stores-only) #35470
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0c24f9e
Replace `Mongo.Collection` with `MinimongoCollection`
tassoevan 1cde585
Implement a Zustand store inside `MinimongoCollection`
tassoevan 386f6e6
Use query keys factory
tassoevan 2ae2e59
Expand store usage
tassoevan 278c595
Replace some `findOne` calls
tassoevan b48a580
Replace some `findOne` calls
tassoevan 31a8457
Add a `state` accessor
tassoevan 0429930
Replace some `findOne` calls
tassoevan 0b5062a
Fork Minimongo
tassoevan ccfaa90
Speed up login in E2EE tests
tassoevan 6f25f2e
Expose more store mutations
tassoevan 7329751
Review some types
tassoevan c49c01d
Wipe stale code comments
tassoevan c4ac397
Replace some collection usage
tassoevan f9ed4d9
Improve ergonomics
tassoevan 7e921ab
Add unit test
tassoevan f0204a5
Refactor `ObserveHandle`
tassoevan 07c5bfa
Adapt nomenclature on `@rocket.chat/mongo-adapter`
tassoevan c8a88c8
Replace the `Sorter` class
tassoevan 5dad72c
Restrict `Matcher` class usage
tassoevan 6b60ebe
Extract observer types
tassoevan 8fe3252
Add JSDoc to `MinimongoCollection`
tassoevan 7a7ddd4
Isolate document updating logic
tassoevan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,8 @@ | ||
import type { IMessage } from '@rocket.chat/core-typings'; | ||
import { Mongo } from 'meteor/mongo'; | ||
|
||
import type { MinimongoCollection } from '../../../../client/definitions/MinimongoCollection'; | ||
|
||
class ChatMessageCollection | ||
extends Mongo.Collection<IMessage & { ignored?: boolean }> | ||
implements MinimongoCollection<IMessage & { ignored?: boolean }> | ||
{ | ||
constructor() { | ||
super(null); | ||
} | ||
|
||
public declare _collection: MinimongoCollection<IMessage & { ignored?: boolean }>['_collection']; | ||
|
||
public declare queries: MinimongoCollection<IMessage & { ignored?: boolean }>['queries']; | ||
} | ||
import { MinimongoCollection } from '../../../../client/lib/cachedCollections/MinimongoCollection'; | ||
|
||
/** @deprecated new code refer to Minimongo collections like this one; prefer fetching data from the REST API, listening to changes via streamer events, and storing the state in a Tanstack Query */ | ||
export const Messages = new ChatMessageCollection(); | ||
export const Messages = new MinimongoCollection< | ||
IMessage & { ignored?: boolean; autoTranslateFetching?: boolean; autoTranslateShowInverse?: boolean } | ||
>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,24 @@ | ||
import type { IRole, IUser } from '@rocket.chat/core-typings'; | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Mongo } from 'meteor/mongo'; | ||
|
||
class UsersCollection extends Mongo.Collection<IUser> { | ||
constructor() { | ||
super(null); | ||
} | ||
|
||
findOneById<TOptions extends Omit<Mongo.Options<IUser>, 'limit'>>(uid: IUser['_id'], options?: TOptions) { | ||
const query: Mongo.Selector<IUser> = { | ||
_id: uid, | ||
}; | ||
|
||
return this.findOne(query, options); | ||
} | ||
import { MinimongoCollection } from '../../../../client/lib/cachedCollections/MinimongoCollection'; | ||
|
||
class UsersCollection extends MinimongoCollection<IUser> { | ||
isUserInRole(uid: IUser['_id'], roleId: IRole['_id']) { | ||
const user = this.findOneById(uid, { fields: { roles: 1 } }); | ||
const user = this.findOne({ _id: uid }, { fields: { roles: 1 } }); | ||
return user && Array.isArray(user.roles) && user.roles.includes(roleId); | ||
} | ||
|
||
findUsersInRoles(roles: IRole['_id'][] | IRole['_id'], _scope: string, options: any) { | ||
roles = Array.isArray(roles) ? roles : [roles]; | ||
|
||
const query: Mongo.Selector<IUser> = { | ||
roles: { $in: roles }, | ||
}; | ||
|
||
return this.find(query, options); | ||
return this.find( | ||
{ | ||
roles: { $in: roles }, | ||
}, | ||
options, | ||
); | ||
} | ||
} | ||
|
||
Object.assign(Meteor.users, { | ||
_connection: undefined, | ||
findOneById: UsersCollection.prototype.findOneById, | ||
isUserInRole: UsersCollection.prototype.isUserInRole, | ||
findUsersInRoles: UsersCollection.prototype.findUsersInRoles, | ||
remove: UsersCollection.prototype.remove, | ||
}); | ||
|
||
/** @deprecated new code refer to Minimongo collections like this one; prefer fetching data from the REST API, listening to changes via streamer events, and storing the state in a Tanstack Query */ | ||
export const Users = Meteor.users as unknown as UsersCollection; | ||
export const Users = new UsersCollection(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.