chore(mongo-adapter): Move update filter logic into the package#36312
chore(mongo-adapter): Move update filter logic into the package#36312kodiakhq[bot] merged 11 commits intodevelopfrom
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
8f8c9b3 to
7138db7
Compare
ea847f5 to
b23aba5
Compare
b23aba5 to
ec7504f
Compare
There was a problem hiding this comment.
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.tswithcreateTransformFromUpdateFilterandcreateUpsertDocument - Rewrite
filter.ts,sort.ts, andlookups.tsto use typedLookupBranchand MongoDB driver types - Cleanup and consolidate helper functions in
common.ts, remove oldcomparisons.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
createDocumentMatcherFromFilterfunction 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
dontIterateflag inbuildResultgoverns whether arrays are expanded. There are no tests covering the behavior whendontIterateis true. Consider adding tests to validate that branches withdontIterateskip nested array expansion.
const buildResult = (arrayIndices: ArrayIndices | undefined, dontIterate: boolean, value: unknown): [LookupBranch] => {
packages/mongo-adapter/src/filter.ts:483
- Using the
Functionconstructor to compile$wherestring expressions can introduce code‐injection risks if untrusted input reaches this logic. Ensure inputs are sanitized or consider deprecating string-based$wheresupport.
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
findModTargetlogic into separate modules to improve readability and ease future maintenance.
import type { Document, Filter, FilterOperators, Sort, UpdateFilter } from 'mongodb';
Proposed changes (including videos or screenshots)
It moves the core of update filter logic from Minimongo to
@rocket.chat/mongo-adapterfor better reuse.Issue(s)
ARCH-1705
Steps to test or reproduce
Further comments