Skip to content

chore(mongo-adapter): Move update filter logic into the package#36312

Merged
kodiakhq[bot] merged 11 commits intodevelopfrom
chore/mongo-adapter-update-filter
Jul 11, 2025
Merged

chore(mongo-adapter): Move update filter logic into the package#36312
kodiakhq[bot] merged 11 commits intodevelopfrom
chore/mongo-adapter-update-filter

Conversation

@tassoevan
Copy link
Contributor

@tassoevan tassoevan commented Jun 26, 2025

Proposed changes (including videos or screenshots)

It moves the core of update filter logic from Minimongo to @rocket.chat/mongo-adapter for better reuse.

Issue(s)

ARCH-1705

Steps to test or reproduce

Further comments

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jun 26, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is targeting the wrong base branch. It should target 7.9.0, but it targets 7.8.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Jun 26, 2025

⚠️ No Changeset found

Latest commit: bf44873

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jun 26, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://RocketChat.github.io/Rocket.Chat/pr-preview/pr-36312/

Built to branch gh-pages at 2025-07-11 14:10 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov
Copy link

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 81.30277% with 155 lines in your changes missing coverage. Please review.

Project coverage is 65.30%. Comparing base (b10ce3b) to head (bf44873).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36312      +/-   ##
===========================================
+ Coverage    64.74%   65.30%   +0.56%     
===========================================
  Files         3156     3156              
  Lines       104912   103991     -921     
  Branches     19957    19895      -62     
===========================================
- Hits         67921    67909      -12     
+ Misses       34303    33398     -905     
+ Partials      2688     2684       -4     
Flag Coverage Δ
e2e 58.36% <59.49%> (+0.78%) ⬆️
unit 70.42% <78.14%> (+0.96%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tassoevan tassoevan force-pushed the chore/mongo-adapter-update-filter branch 7 times, most recently from 8f8c9b3 to 7138db7 Compare July 4, 2025 19:35
@tassoevan tassoevan force-pushed the chore/mongo-adapter-update-filter branch from ea847f5 to b23aba5 Compare July 8, 2025 15:53
@tassoevan tassoevan force-pushed the chore/mongo-adapter-update-filter branch from b23aba5 to ec7504f Compare July 9, 2025 19:31
@tassoevan tassoevan changed the title chore(mongo-adapter): ... chore(mongo-adapter): Move update filter logic into it Jul 9, 2025
@tassoevan tassoevan changed the title chore(mongo-adapter): Move update filter logic into it chore(mongo-adapter): Move update filter logic into the package Jul 9, 2025
@tassoevan tassoevan requested a review from Copilot July 9, 2025 19:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This chore moves the update-filter logic into the mongo-adapter package and refactors related filter/sort/lookups utilities for consistency with MongoDB driver types.

  • Introduce updateFilter.ts with createTransformFromUpdateFilter and createUpsertDocument
  • Rewrite filter.ts, sort.ts, and lookups.ts to use typed LookupBranch and MongoDB driver types
  • Cleanup and consolidate helper functions in common.ts, remove old comparisons.ts

Reviewed Changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/mongo-adapter/src/updateFilter.ts New module for transforming and upserting with modifiers
packages/mongo-adapter/src/filter.ts Rewrite of filter compiler using branched matchers
packages/mongo-adapter/src/sort.ts Rename and refactor compileSort to createComparatorFromSort
packages/mongo-adapter/src/lookups.ts Rewrite lookup logic to emit LookupBranch entries
packages/mongo-adapter/src/common.ts Consolidate shared utilities (clone, assertions, etc.)
packages/mongo-adapter/src/types.ts Remove old FieldExpression/Filter types
packages/mongo-adapter/src/index.ts Export updated APIs
packages/mongo-adapter/src/*.spec.ts Updated tests for new implementations
apps/meteor/... Update imports to use new package APIs and driver types
Comments suppressed due to low confidence (5)

packages/mongo-adapter/src/index.ts:3

  • [nitpick] The createDocumentMatcherFromFilter function appears to be an internal helper. Exposing it in the public index may lead users to rely on an unstable API surface. Consider keeping it private or clearly marking it as experimental in documentation.
export { createPredicateFromFilter, createDocumentMatcherFromFilter } from './filter';

packages/mongo-adapter/src/updateFilter.ts:494

  • This is a major entry point for users applying update filters. Adding JSDoc comment describing expected inputs, optional parameters, and error cases would help users integrate it correctly.
export const createTransformFromUpdateFilter = <T extends { _id: string }>(modifier: UpdateFilter<T>) => {

packages/mongo-adapter/src/lookups.ts:4

  • The dontIterate flag in buildResult governs whether arrays are expanded. There are no tests covering the behavior when dontIterate is true. Consider adding tests to validate that branches with dontIterate skip nested array expansion.
const buildResult = (arrayIndices: ArrayIndices | undefined, dontIterate: boolean, value: unknown): [LookupBranch] => {

packages/mongo-adapter/src/filter.ts:483

  • Using the Function constructor to compile $where string expressions can introduce code‐injection risks if untrusted input reaches this logic. Ensure inputs are sanitized or consider deprecating string-based $where support.
		selectorValue = Function('obj', `return ${selectorValue}`) as (this: T, doc: T) => boolean;

packages/mongo-adapter/src/updateFilter.ts:1

  • [nitpick] This file is over 600 lines and implements all update operators inline. Consider splitting each operator or the findModTarget logic into separate modules to improve readability and ease future maintenance.
import type { Document, Filter, FilterOperators, Sort, UpdateFilter } from 'mongodb';

@tassoevan tassoevan marked this pull request as ready for review July 10, 2025 20:10
@tassoevan tassoevan requested a review from a team as a code owner July 10, 2025 20:10
@ggazzo ggazzo added this to the 7.9.0 milestone Jul 11, 2025
@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Jul 11, 2025
@dionisio-bot dionisio-bot bot removed the stat: QA assured Means it has been tested and approved by a company insider label Jul 11, 2025
@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Jul 11, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 11, 2025
@kodiakhq kodiakhq bot merged commit e2736a0 into develop Jul 11, 2025
51 checks passed
@kodiakhq kodiakhq bot deleted the chore/mongo-adapter-update-filter branch July 11, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants