RocketChat / RocketChat/Rocket.Chat

Use Document[] for aggregation pipeline types in MessagesRaw

Open
#38,896 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: feature
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

  • Document is already imported from mongodb and IMessage is already imported from @rocket.chat/core-typings
  • No runtime behavior changes, types only
  • Resolves the existing // FIXME: aggregation type definitions comment
  • The following variables should be typed as Document:
    • match
    • lookup
    • unwind
    • group
    • project
    • sort
  • The following arrays should be typed as Document[]:
    • firstParams
    • params
  • The following object should be typed as Filter<IMessage>:
    • query
  • The following object should be typed as UpdateFilter<IMessage>:
    • update

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.