RocketChat / RocketChat/Rocket.Chat
Use Document[] for aggregation pipeline types in MessagesRaw
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Description
In MessagesRaw.ts, the aggregation pipeline stages are typed using a brittle workaround:
Expected Behavior
Pipeline stages should be typed as Document[] which is the correct type from the MongoDB driver and is already imported in the file.
Current Behavior
const match = { $match: { ... } };
const lookup = { $lookup: { ... } };
const unwind = { $unwind: { ... } };
const group = { $group: { ... } };
const project = { $project: { ... } };
const firstParams: Exclude<Parameters<Collection<IMessage>['aggregate']>[0], undefined> = [match, lookup, unwind];
const sort = { $sort: options.sort || { name: 1 } };
const params = [...firstParams, group, project, sort];
const query = { 'u._id': userId, '$or': [{ 'file._id': { $exists: true } }, { 'files._id': { $exists: true } }], };
const update = { $set: { _hidden: hidden, },};
Steps to Reproduce
See packages/models/src/models/Messages.ts
Additional Context
Documentis already imported frommongodbandIMessageis already imported from@rocket.chat/core-typings- No runtime behavior changes, types only
- Resolves the existing
// FIXME: aggregation type definitionscomment - The following variables should be typed as
Document:matchlookupunwindgroupprojectsort
- The following arrays should be typed as
Document[]:firstParamsparams
- The following object should be typed as
Filter<IMessage>:query
- The following object should be typed as
UpdateFilter<IMessage>:update
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open packages/models/src/models/Messages.ts and locate the FIXME about aggregation type definitions and the MessagesRaw implementation. Read the existing mongodb imports and the aggregation setup, then apply the requested Document, Document[], Filter, and UpdateFilter annotations to the named variables. Done means the brittle workaround is removed without runtime changes and the file's type checks pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, typescript
- Domain
- databases
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100